Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

difference between 'a=++a + a++' and 'a=a++ + ++a'

–1 vote
asked Dec 13, 2018 by nikita04sharma08 (110 points)

7 Answers

0 votes
answered Dec 13, 2018 by anonymous
there is no difference
0 votes
answered Dec 17, 2018 by anonymous
yeah it is same
0 votes
answered Dec 19, 2018 by Anurag Sharma (140 points)
There is no such difference. Assume a = 5 , one will get the same output as 12.
0 votes
answered Dec 26, 2018 by Mohammad Saeidi (140 points)

(a++)+(++a) + 1 = (++a)+(a++)

yes

commented Dec 26, 2018 by Mohammad Saeidi (140 points)
in C is not equal.
but in in C++ this is equal.
0 votes
answered Dec 26, 2018 by Awanish (140 points)

There is no any difference in it

0 votes
answered Dec 26, 2018 by anonymous
N0 DIFFERENCE
0 votes
answered Dec 29, 2018 by Jay (140 points)
Specifically for C/C++, If 'a' is assigned an initial value of 1:

a=++a + a++ would be equivalent to a = 2 + 2

This example increments 'a' to value 2 before evaluating the left side of the sum, then evaluates the right side of the sum (takes 2) before incrementing 'a' to value 3.  Finally the sum (4) is assigned to 'a'.

a=a++ + ++a would be equivalent to a = 1 + 3

This example starts by evaluating the left side of the sum (takes 1) before incrementing 'a' to value 2, then increments 'a' to value 3 before evaluating the right side of the sum.  Finally the sum (4) is assigned to 'a'.

The final result is the same, but the compiler likely won't get the the result in the same order.  Some compiler implementations might optimize this to be identical however.  See expression trees for more information.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...