Trace the execution of this program segment and write the ou

Trace the execution of this program segment and write the outputs accordingly. #include using namespace std; int main() {int *p = new int; int *q = new int; cout

Solution

Answer:

0x11e7c20 0x11e7c40 10 20 20 10 30 30 10 4 30

first cout will print the address of two variables p and q.

q value is assigned to r variable. since both are same pointer variable both will refer same memory location.

second count will print p = 10 q value = 20 and r value = 20

we again reassign value that is addition of p and q to r. now r value is 30. since q and r refer same memory location q value is also 30

so third cout will print p = 10 and q = 30 and r =30

now we are reassinging a new momory location to q by new operator so now relation between q and r broken.

now we assigned 4 to q variable

now fourth cout will print p =10 and q =4 and r =30.

 Trace the execution of this program segment and write the outputs accordingly. #include using namespace std; int main() {int *p = new int; int *q = new int; co

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site