C Programming - Pointers - Discussion

Discussion Forum : Pointers - Find Output of Program (Q.No. 3)
3.
What will be the output of the program ?
#include<stdio.h>

int main()
{
    int x=30, *y, *z;
    y=&x; /* Assume address of x is 500 and integer is 4 byte size */
    z=y;
    *y++=*z++;
    x++;
    printf("x=%d, y=%d, z=%d\n", x, y, z);
    return 0;
}
x=31, y=502, z=502
x=31, y=500, z=500
x=31, y=498, z=498
x=31, y=504, z=504
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
92 comments Page 8 of 10.

Vikash said:   1 decade ago
Someone please tell.
Why compiler doesn't execute

y++ = z++;

while execute *y++ = *z++;

Mayur said:   1 decade ago
*y++ means *(y++)
if u want to increase value of y then
(*y)++ is correct syntax....

Amol said:   1 decade ago
*y++=*z++ can broken down as
*y=*z;
y++;
z++;
Because it is post increment operator.

Prince said:   8 years ago
Can anyone tell depending on the size of integer *y++ value will increment by 4?

Rajakumar said:   1 decade ago
&x=500
x=3
y=&x so y=500;
z=y so y=z=500;
so *y++=*z++ =504
and x++=31

Anusha katta said:   1 decade ago
How is the answer D?.

And can anyone tell the significance of, *y++=*z++; ?.

Ripu n ajit said:   1 decade ago
As x=30; y=z= 500;

*z++=504= *y++;

x++=31;

So the answer is 31, 504, 504.

PRAVEER said:   6 years ago
It is already given that size is 4.

As it depends on 16byte or 32byte?
(1)

Doubt said:   1 decade ago
Can anybody explain in detail how *y++ gets the value 504 why not 31 ?

Nitis said:   6 years ago
Address size will be 2 byte, then how it can be 504?

It should 502.
(2)


Post your comments here:

Your comments will be displayed after verification.