Examveda
Examveda

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);
}

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.


This Question Belongs to C Program >> Control Structures

Join The Discussion

Comments ( 2 )

  1. Ravindra Mulane
    Ravindra Mulane :
    6 years ago

    2%5 is 2 & not 0

  2. Satyendra Gupta
    Satyendra Gupta :
    7 years ago

    10 0 100

Related Questions on Control Structures