Discussion :: Control Structures
-
What will be the output of the given program?
#include<stdio.h>
void main()
{
int value1, value2=100, num=100;
if(value1=value2%5) num=5;
printf("%d %d %d", num, value1, value2);
}
Answer : Option D
Explanation :
Expression value2%5 is equal to 0 and this value assigned to value1.
Therefore
if
condition reduces to
if(0)
so it fails.
Therefore body of
if
will not be executed i.e
num = 5
will not be assigned.
So at printf num = 100 , value1 = 0 and value2 = 100.
Be The First To Comment