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 .


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...

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.

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...


Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.