C Programming :: Declarations and Initializations - Discussion
11 / 54
#include<stdio.h>
int main()
{
int x,y=2,z,a;
x = (y*=2) + (z=a=y);
printf ("%d", x);
return 0;
}
#include<stdio.h>
int main()
{
int x,y=2,z,a;
x = (y*=2) + (z=a=y);
printf ("%d", x);
return 0;
}
A7
B8
C6
Dsyntactically wrong
Show Explanation
x = (y*=2) (z=a=y); Meaning of y*=2 means y=y*2 hence y value becomes 2*2=4.
Current value of y =4 so z=a=y=4.
Hence x=4+4=8
Asked In ::
x = (y*=2) (z=a=y); Meaning of y*=2 means y=y*2 hence y value becomes 2*2=4.
Current value of y =4 so z=a=y=4.
Hence x=4+4=8
Read Full Answer
Report Error
Please Login First Click Here
In line 5, let us divide the expression x=(y*=2)+(z=a=y) into two parts i.e., (y*=2) and (z=a=y).
The first part i.e., (y*=2) can also be written as (y=y*2). Also y is initialized earlier with the value 2, so the new value of y will be (y=2*2=4).
The second part i.e., (z=a=y) where y is 4, which means a=4, which also means z=4.
So, finally the value of x can be calculated as x=4+4=8, so the correct option is B.
Read Full Answer
Report Error
Please Login First Click Here