Variation in the working of the comma operator in the below codes
Consider the following code snippets
Case1:
int main()
{
int a;
a=printf("hello"),printf("joke");
printf("%d",a);
return 0;
}
Case2:
int main()
{
int a;
a=(printf("hello"),printf("joke"));
printf("%d",a);
return 0;
}
Case3:
int main()
{
int a;
a=10>8?(printf("hello"),printf("joke"))😛rintf("hello");
printf("%d",a);
return 0;
}
Case4:
int main()
{
int a;
a=10>8?printf("hello"),printf("joke")😛rintf("hello");
printf("%d",a);
return 0;
}
I am unable to catch out the reason that when I use paranthesis in case 2,then I get the output as hellojoke4,while without using parantheis I get the output as hellojoke5.
As per the output it is when I tried using ternary operator ,then the same expression when executed using paranthesis or without using paranthesis,returns the last output value of printf statement that is hellojoke4 ,so how does altogether the behaviour differs in the case of ternary operator.
And how does the presence of paranthesis affects the working of the comma ,does it act like a separator or as an operator.
Case1:
int main()
{
int a;
a=printf("hello"),printf("joke");
printf("%d",a);
return 0;
}
Case2:
int main()
{
int a;
a=(printf("hello"),printf("joke"));
printf("%d",a);
return 0;
}
Case3:
int main()
{
int a;
a=10>8?(printf("hello"),printf("joke"))😛rintf("hello");
printf("%d",a);
return 0;
}
Case4:
int main()
{
int a;
a=10>8?printf("hello"),printf("joke")😛rintf("hello");
printf("%d",a);
return 0;
}
I am unable to catch out the reason that when I use paranthesis in case 2,then I get the output as hellojoke4,while without using parantheis I get the output as hellojoke5.
As per the output it is when I tried using ternary operator ,then the same expression when executed using paranthesis or without using paranthesis,returns the last output value of printf statement that is hellojoke4 ,so how does altogether the behaviour differs in the case of ternary operator.
And how does the presence of paranthesis affects the working of the comma ,does it act like a separator or as an operator.
0