info about give program below

Status
Not open for further replies.

praveenkumar450

Newbie level 5
Joined
Jul 2, 2014
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
Hyderabad, Andhra Pradesh, India
Activity points
55

Code C - [expand]
1
2
3
4
5
6
7
8
9
#include<stdio.h>
int main()
{
int a=6,b=8;
printf("%d\t",a=b);
printf("%d\t",a==b);
printf("%d  %d\n",a,b);
return 0;
}



and the output is
6 1 6 6
can i know why it 6 1 6 6
and for what it is executing like that
 
Last edited by a moderator:

the output should be
8 1 8 8
Code:
printf("%d\t",a=b);
assigns a the value of b, the result of the expression 8 is printed
Code:
printf("%d\t",a==b);
compares a with b and as both values are 8 the result is 1 (true)
Code:
printf("%d 	%d\n",a,b);
prints a and b both have the value 8
 

= operator will be executed as right to left.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…