Examveda
Examveda

What will be the output of the given program?
#include<stdio.h>
void main()
{
	int a=11,b=5;
	if(a=5) b++;
	printf("%d %d", ++a, b++);
}

A. 12 7

B. 5 6

C. 6 6

D. 6 7

E. 11 6

Answer: Option C

Solution(By Examveda Team)

Here if condition evaluates to true as a non-zero value i.e 5 is assigned to a.
So the value of a = 5 and after increment value of b = 6.
In printf statement due to pre-increment of a value of a printed will be 6 and due to post-increment of b value of b printed will be 6 and not 7.


This Question Belongs to C Program >> Control Structures

Join The Discussion

Related Questions on Control Structures