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 ...
|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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; |
![]() |
| Thread Tools | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) | Steve Summit | Tech FAQ | 0 | 06-15-2004 07:00 AM |
| comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) | Steve Summit | Tech FAQ | 0 | 06-01-2004 07:01 AM |
| comp.lang.c Answers to Frequently Asked Questions (FAQ List) | Steve Summit | Tech FAQ | 0 | 06-01-2004 07:00 AM |
| comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) | Steve Summit | Tech FAQ | 0 | 05-15-2004 07:00 AM |
| Apple II Csa2 FAQs: Telecom Hardware & Transfers, Part 20/25 | rubywand@swbell.net | Tech FAQ | 0 | 04-04-2004 08:29 AM |