var x=7; var y=x++; var z = y++ % x; alert(z) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

var x=7; var y=x++; var z = y++ % x; alert(z)

can anybody help with this question?

11th May 2018, 9:59 PM
Lindy Ramirez 🇺🇸🇧🇿
Lindy Ramirez 🇺🇸🇧🇿 - avatar
3 Answers
+ 3
x=7 y=7,x=8 z=7%8=7<-alert y=8 So its 7
12th May 2018, 2:12 AM
syul
syul - avatar
+ 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
12th May 2018, 2:14 AM
syul
syul - avatar
+ 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)!
12th May 2018, 7:52 AM
Naveen Maurya
Naveen Maurya - avatar