What is the output of code fragments


Discuss the below:

Q1. What is the output of the following C++ code?

int x;
int y;
int *p = &x;
int *q = &y;
*p = 35;
*q = 98;
*p = *q;
cout << x << " " << y << endl;
cout << *p << " " << *q << endl;

Q2. What is the output of the following C++ code?

int x;
int y;
int *p = &x;
int *q = &y;
x = 35; y = 46;
p = q;
*p = 78;
cout << x << " " << y << endl;
cout << *p << " " << *q << endl;

Q3. What is the output of the following C++ code?

int *p;
int *q;
p = new int;
q = p;
*p = 46;
*q = 39;
cout << *p << " " << *q << endl;

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: What is the output of code fragments
Reference No:- TGS01937050

Now Priced at $20 (50% Discount)

Recommended (98%)

Rated (4.3/5)