+ 3
#include <iostream> using namespace std; int main() { int a=0,u=0; u=(a) * ++a; cout<<u; }
ans is 1 can someone explain
12 Respuestas
+ 4
You don't post the question with your answer than you have write.
https://www.sololearn.com/discuss/1316935/?ref=app
+ 3
Mark We called the increment and decrement.
a += 1 has remplaced by a++ but ++a can't change the number because the ++ is the left of a.
+ 3
Here is what the C standard says:
C11: 6.5 Expressions:
If a side effect on a scalar object is unsequenced relative to either a different side effect on the same scalar object or a value computation using the value of the same scalar object, the behavior is undefined. If there are multiple allowable orderings of the subexpressions of an expression, the behavior is undefined if such an unsequenced side effect occurs in any of the orderings.84).
+ 2
mark u get 1 only after interchanging..
+ 2
by the way my doubt is that
parameters should be solved first
so it become
u=(0)*1
+ 2
0 on gcc x64
+ 1
this is undefined behaviour. some compilers read the arguments from left to right, and others right to left.
+ 1
ooppps
+ 1
Hi guys,
So, I checked everything again and tested in other compilers, and I notice that different compilers will give different results.
For example, clang will give the warning -Wunsequenced, saying unsequenced modification and access to "a".
Thus, in the end this is an undefined behaviour, as Bebida Roja mentioned.
0
i think it because of you make an ++a.... so the compiler will do the a+1 before the u=(a)*++a.... so it would be 1×1
0
answer is 1
0
++a matlab change then use so a=1. now , a=1 so answer is 1*1=1