I was implementing this code in Pelles C. Please explain how this works.Code:#include<stdio.h> int main(void) { int i=4,j=-1,k=0,w,x,y,z; w=i||j||k; x=i&&j&& k; y=i||j&&k; z=i&&j||k; printf("\w=%d x=%d y=%d z=%d",w,x,y,z); }
I was implementing this code in Pelles C. Please explain how this works.Code:#include<stdio.h> int main(void) { int i=4,j=-1,k=0,w,x,y,z; w=i||j||k; x=i&&j&& k; y=i||j&&k; z=i&&j||k; printf("\w=%d x=%d y=%d z=%d",w,x,y,z); }
If you don't understand it, why were you implementing it?
How about you try to explain it to us, and we'll tell you if you're correct.
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers
"Hi, I got this homework/test question and I don't feel like thinking about it. Please provide me with the answer."
I don't feel like thinking about your homework either. I don't get the grade, you do.
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers
Code:#include<stdio.h> // preprocessor directive int main(void) // "main()" function { int i=4,j=-1,k=0,w,x,y,z; // variable declarations w=i||j||k; // define value for 'w' x=i&&j&& k; // define value for 'x' y=i||j&&k; // define value for 'y' z=i&&j||k; // define value for 'z' printf("\w=%d x=%d y=%d z=%d",w,x,y,z); // prints the values of 'w', 'x', // 'y', and 'z' to the screen // what, no return value? }
Terrible Matticus! You didn't line up your comments nice and neatly!
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers
I'm intrigued now! I might just compile it and see what happens!
(seriously, I have no idea if you can use logic operators in variable assignments! EDIT: It seems as though you can. Interesting...)
Last edited by The Doctor; 09-18-2012 at 04:55 PM.
Code:if (codeWorks( code) && !youCanDoSomethingBetter( code) ) { beHappy(); } else { fixCode( code); }
How this works is that you search the web for a programming forum, then sign up without reading the rules of the site and often without reading the FAQ, then you possibly post code and expect the contributors to tell you everything you need to know about it. Usually this is without code tags, though we are obviously sometimes lucky there. Then the contributors get annoyed at you for being too stupid to not just search for the exact code using the very same search engine to begin with, since it is bound to have been asked about a thousand times already, and for being too lazy to look up how the various language constructs themselves work. such that you might have been able to solve the problem on your own, or at least post a good attempt at understanding it, and learn it better. Then you get berrated for the above, and either lash out at those who point out the shortcomings of your approach to getting help, or you simply disappear and don't come back. Or sometimes you get told about this article, which you read and then understand the problem. Or in some cases you even actually realise how you messed up your approach to getting help initially, then change your ways and stick around and eventualy learn something.
Yeah that mostly sums it up, glad I could help!
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
Think about how
andCode:while( 1 ){ }
are both valid expressions. Also think about how the second expression evaluates inside the test expression.Code:while( j || k || r ){ }