what will be the output of the following lines of code

I was asked this question in a technical interview and i was not aware about it. Please help me to understand this code.

#include<iostream.h>
int main()
{
int a=5, b=6;
int c;
c= a,b;
c=(a,b);
cout<<c;
return 0;
}

on runing this code i got the output as c=5 and c=6. I can't understand what is going on here in these two lines.Please help.
on this line c= a,b; the assignment operator has higher precedence than the , operator so assignment is done first so c = 5;

on this line c=(a,b); the parenthesis make the comma operator evaluate first the comma operator returns its right hand operand so (a,b) evaluates to 6 so then you have c = 6;
Did they give any reason why they were expecting you to know such pointless detail, that could be trivially looked up if it ever actually became an issue?

Topic archived. No new replies allowed.