What is the ouput for the following code?
int x;
int y;
int *p = %26amp;x;
int *q = %26amp;y;
*p = 35;
*q = 98;
*p = *q
cout %26lt;%26lt; x %26lt;%26lt; " " %26lt;%26lt; y %26lt;%26lt; endl;
cout %26lt;%26lt; *p %26lt;%26lt; " " %26lt;%26lt; *q %26lt;%26lt; endl;
C++ Question... Im new here thank you for your help!?
int x;
int y;
int *p = %26amp;x;
int *q = %26amp;y;
*p = 35;//it means x=*p=31
*q = 98;//it means y=*q=98
*p = *q;//it means *p=*q=x=y=98
cout %26lt;%26lt; x %26lt;%26lt; " " %26lt;%26lt; y %26lt;%26lt; endl;
cout %26lt;%26lt; *p %26lt;%26lt; " " %26lt;%26lt; *q %26lt;%26lt; endl;
so result is
98 98
98 98
Reply:98 98
98 98
Reason: *p is same as x, *q is same as y. The line *p = *q makes both of them 98.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment