Possible Duplicate:
What does the ',' operator do in C?
Ok I had an interview today and they asked me what should be the output of the following code
#include<stdio.h>
int main ()
{
int a=1,b=1;
char c='0';
if(a,b,c)
printf("wow \n");
}
after running it on my machine I am able to get the answer but I was not able to answer there.I want to know if such a if statement is allowed? Where is it mentioned?
My problem is the if condition mentioned above I am not able to understand how does that if statement work.
**UPDATE **
I did not found any such thing in K&R can any one recommend a good book.I have programmed things and not new to C but still after failing this question I want to once more look if some more C concepts in depth (specially such as above) are mentioned where can I read.
The comma expression a,b,c
just takes the value of the last value, c
which has the character value '0'
, which has a numeric value of 48. So the expression evaluates to true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With