What will be output of the following program?
#include<stdio.h>
void main(){
int x;
x=10,20,30;
printf("%d",x);
return 0;
}
Explanation
Output:
Turbo C++ 3.0: 10
Turbo C ++4.5: 10
Linux GCC: 10
Visual C++: 10
Explanation :
Precedence table:
Operator
|
Precedence
|
Associative
|
=
|
More than ,
|
Right to left
|
,
|
Least
|
Left to right
|
Since assignment operator (=) has more precedence than comma operator .So = operator will be evaluated first than comma operator. In the following expression
x = 10, 20, 30
First 10 will be assigned to x then comma operator will be
evaluated.
No comments:
Post a Comment