
- Forum
- Programming Talk
- C and C++
- Result of Program
Result of Program
This is a discussion on Result of Program within the C and C++ forums, part of the Programming Talk category; I have idea about prefix and postfix operators and operations using these operators in C programming language. But I am ...
-
Result of Program
I have idea about prefix and postfix operators and operations using these operators in C programming language. But I am confused about the following program?
main()
{
int a=5,b=0;
y=a+++a+++a;
printf(" a=%d b=%d ",a,b);
}
How will the above get solved? I am confused on the operations. Kindly someone help me out.
-
The precedence of operators is first Postfix increment/decrement operator and the associativity for this is from left-to-right.
So we have a++ gets evaluated first and so the expression first becomes
y=a+++a+++a;
y=5+5+5=15
and then a gets increment twice and so a becomes 7
So your output would be
a=7 b=15;
But a small typo error you have made is instead of b=a+++a+++a; You have given as y=a+++a+++a;

Reply With Quote





