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 10 of 10.

Sadaf Rahman said:   1 decade ago
In a pointer char stores 2 bytes, int stores 4 bytes, long stores 8 bytes.

Hence in above example x=504 and y=504.

Sundeep katta said:   1 decade ago
Since Z and y have same values in them y.

The statment *y++=*z++ actually assigns the value in z (address of x)to ythus Y++ makes it 500, similarly z++.


Post your comments here:

Your comments will be displayed after verification.