C Programming :: Declarations and Initializations - Discussion
10 / 54
#include<stdio.h>
void main()
{
int x,y=2,z,a;
if(x=y%2)
z=2;
a=2;
printf("%d %d",z,x);
}
#include<stdio.h>
void main()
{
int x,y=2,z,a;
if(x=y%2)
z=2;
a=2;
printf("%d %d",z,x);
}
A1..0
B2..0
C2..1
DGarbage-value 0
ECompilation Error
Show Explanation
Asked In ::
In line 5, in the 'if' part, the value of x will be calculated as (x=2%2) and x will be initialized with the value 0 i.e., if(0). In C, whenever the test expression inside 'if' is 0, then the compiler never executes that 'is' statement. Basically it means that "0 is not 0", which is false statement as 0 is always 0. So z will not be initialized with 2. At the time of printing, z will be initialized with some garbage value, and that garbage value will get displayed, while the value of x will be displayed as 0. So, the correct option will be option D.
Read Full Answer
Report Error
Please Login First Click Here
if(x=y%2)..........2%2 will give remainder value i.e=0 hence x=0 so if(0)
z=2; ....z value wont be initalised as if condition is not properly defined hence garbage value
a=2;
printf("%d %d",z,x);,...........Garbage value for z and 0 for x will be printed.
Read Full Answer
Report Error
Please Login First Click Here