Question:What will be output when you will execute following c code?#include<stdio.h>
void main(){
int a=2;
if(a--,--a,a)
printf("The Dalai Lama");
else
printf("Jim Rogers");
}
Choose all that apply:
A The Dalai Lama
B Jim Rogers
C Run time error
D Compilation error: Multiple parameters in
if statement
E None
+ ExplanationConsider the following expression:
a-- , --a , a
In c comma is behaves as separator as well as operator.In the above expression comma is behaving as operator.Comma operator enjoy lest precedence in precedence table and its associatively is left to right. So first of all left most comma operator will perform operation then right most comma will operator in the above expression.
After performing a-- : a will be 2
After performing --a : a will be 0
a=0
As we know in c zero represents false and any non-zero number represents true. Hence else part will execute.