find the value of the variables after executing the following statements
1. int a=1, b=2, c;
b=a++ + ++a;
c=++a + b++
Answers
Answer:
Depends on the programming language: the question is not specifying one. Different languages - different rules.
In languages where “+++” is not an operator and both “++” and “+” are, three plusses in a row typically parse as “++ +”, giving “++c++ + c”. In C and C++ and Java, that is ill-formed (cannot be compiled)
If you were to add a space to make that into “++c + ++c”, the resulting expression is undefined in C and C++: the program that attempts to evaluate this is meaningless and any value you may see in a given test (I notice some other answers bring up 24 and 23) is also just noise from a broken program.
Answer:
a=4
b=5
c=8
Explanation:
b=a++(a=1 +1 =2(post increment=>take a=1))+ ++a(a=1+2=3(pre increment=>take a=3))
b=4
c=++a(a=1+3=4(pre increment=>take a=4))+ b++(b=4+1=5(post increment=>take b=4))
c=8
hence a=4,b=5,c=8