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);
}
#include<stdio.h>
void main()
{
int value1, value2=100, num=100;
if(value1=value2%5) num=5;
printf("%d %d %d", num, value1, value2);
}
A. 100 100 100
B. 5 0 20
C. 5 0 100
D. 100 0 100
E. 100 5 100
Answer: Option D
Solution(By Examveda Team)
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.
Join The Discussion
Comments ( 2 )
Which control structure is used to repeatedly execute a block of code in C?
A. for loop
B. if statement
C. switch case
D. while loop
In C, what is the purpose of the 'break' statement within a loop?
A. Continue to the next iteration
B. Exit the program
C. Terminate the loop and exit it
D. Skip the current iteration
What is the purpose of the 'else' statement in C's 'if-else' control structure?
A. Execute the 'if' block
B. Execute the 'else' block
C. Execute both 'if' and 'else' blocks
D. Skip the 'if' block
Which control structure is used to make a decision between two or more alternatives in C?
A. switch case
B. for loop
C. if statement
D. while loop
2%5 is 2 & not 0
10 0 100