0

Hello im practicing C language
and i ran into this code and i can't figure out the outputs :(
can u help me please ?
I'm confused in operator precedence.
and What does short circuit evaluation means in c?

when i run this code the output is:
000 and 001
How come this way ? please share ur knowledge with me .

#include<stdio.h>

void main()
{
	int a = 0, b = 0, x;

	x = 0 && (a = b = 777);
	printf("%d %d %d\n", a, b, x);

	x = 777 || (a = ++b);
	printf("%d %d %d\n", a, b, x);
}

Thanks much...

2
Contributors
2
Replies
3
Views
12 Years
Discussion Span
Last Post by free_eagle
0

Don't use void main().

and What does short circuit evaluation means in c?

if(a() && b())

In this case, if a is false, b won't be evaluated, because no matter what b is, the expression is false.

0

hi DWKS
thanks for short clear explanation.

So u in this case when we use logical operations we don't assign numbers but we think it like true and false right and we can think of "if" statement to be considered?!

aah yes i understood that i didn't think about condition i thought may be we assign 777 to a and b :)

but look this operators;

"=" and "==" x = 0 && (a = b = 777)

i though as the operator is assignment it will give 0 to x and ... umm okay i'll try to find out...

THANK YOU!!!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.