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.

Replies

You are reading an archived discussion.

Related Posts

Microsoft is trying to make Windows 10 the perfect operating system for every user around the globe. As Microsoft’s Windows OS is a globally availabke product, it should support all...
Project Abstract / Summary : 1)Autonomous mode- The project consists of a Firebird V Atmega 2560 Robot. There are two fields on either side of a white line(fig.1.1). The robot...
Project Abstract / Summary : Cloud-based Mobile Media Applications with Service populating and QoS-Aware Mechanisms Chaitali Autade, Trupti Hon, Akshada Avhad, Shaila Kakade Computer Department of Sanjivani Rural Education Society’s...
Project Abstract / Summary : A proposed proxy-based multicloud computing framework allows dynamic, on the fly collaborations and resource sharing among cloud-based services, addressing trust, policy, and privacy issues without...
Hello all, You must be superlatively good at handling codes, so pardon my lack of knowledge for I have only coded on Windows and only on VS. I have recently...