¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita0
var x=7; var y=x++; var z = y++ % x; alert(z)
can anybody help with this question?
3 Respuestas
+ 3
x=7
y=7,x=8
z=7%8=7<-alert
y=8
So its 7
+ 3
When a postfix operator is applied to a function argument, the value of the argument is not guaranteed to be incremented or decremented before it is passed to the function. See section 1.9.17 in the C++ standard for more information.
So you need to run a compiler to check out
Its c++ but postfix are kinda same in all languages
+ 2
var x = 7;
//x is initialized and assigned the value 7
var y = x++;
//y is initialized and assigned the value of x(7), and then x is increased to 8;
var z = y++ % x;
//z is initialized and assigned the value of y(7) % x, but then y is increased to 8, and so z becomes 7 % 8, which is 7
alert(z);
//Note that the postfix increment operator (a++) follows the policy "use, then change", while it's the opposite in the prefix increment operator (++a)!