| | |
i can't figure out this code :( help please
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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 .
Thanks much...
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 .
C Syntax (Toggle Plain Text)
#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...
Learn to forgive ,answer with kindness to evel...
Live happily and love sincerely... [/COLOR]
Live happily and love sincerely... [/COLOR]
Don't use void main().
In this case, if a is false, b won't be evaluated, because no matter what b is, the expression is false.
•
•
•
•
and What does short circuit evaluation means in c?
C Syntax (Toggle Plain Text)
if(a() && b())
dwk
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
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!!!
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!!!
Learn to forgive ,answer with kindness to evel...
Live happily and love sincerely... [/COLOR]
Live happily and love sincerely... [/COLOR]
![]() |
Similar Threads
- Forms Authorization/ Authentication using asp .net and vb .net (ASP.NET)
- Need help with this code (JavaScript / DHTML / AJAX)
- Giving code to posters rather than helping them (IT Professionals' Lounge)
- Please help me figure out whats wrong with my code (C++)
- Hello Everyone, I need Help with my C++ Code... (C++)
Other Threads in the C Forum
- Previous Thread: Socket communication and event handling <C>
- Next Thread: data sorts in reverse order!! help!!
| Thread Tools | Search this Thread |
#include * ansi array arrays asterisks bash binarysearch calculate centimeter changingto char character convert copyanyfile copyimagefile creafecopyofanytypeoffileinc createprocess() database dynamic execv fgets file floatingpointvalidation fork framework function getlogicaldrivestrin givemetehcodez grade gtkwinlinux histogram ide inches include infiniteloop initialization input interest intmain() iso keyboard km license linked linkedlist linux list looping lowest matrix meter microsoft number oddnumber open opendocumentformat openwebfoundation owf pdf pointer pointers posix power probleminc process program programming pyramidusingturboccodes radix read recursion recv recvblocked research reversing scheduling segmentationfault send sequential single socket socketprogramming standard strchr string suggestions systemcall test testautomation testing threads turboc unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi





