Last Updated :
14 Nov, 2018
Consider the following C program:
#include
int main()
{
int a = 0, b =1, c = a, d = 2;
if(a, b, c, d)
printf(\”GeeksforGeeks\\n\”);
if(a, b, c)
printf(\”A Computer Science Portal for Geeks\”);
}
What will be the output of the above program?
(A) GeeksforGeeks
(B) A Computer Science Portal for Geeks
(C) GeeksforGeeks
A Computer Science Portal for Geeks
(D) Compilation Error
Answer: (A)
Explanation: According to associativity of the comma operator is from left to right only the right-most value will be returned and all other values evaluated are ignored.
Since last value returned in the first while is non zero but in the second while it is zero. So, the only first loop will be executed and \’GeeksforGeeks\’ will be printed.
So, option (A) is correct.
Quiz of this Question
Share your thoughts in the comments
Please Login to comment...