- 3

if x=5 then --x; y=--x; x=4 and y=4 but x--; y=x--; x=4 and y=5 right or wrong?

This is true or false

20th Jul 2016, 9:04 AM
Avishek Raj Panta
Avishek Raj Panta - avatar
4 Respuestas
+ 2
the First one results in x and y = 3. because you have x=5, --x == predecrement x-1=4 y=--x == predecrement x-1=3 and store in y print x and y 2nd ends with x=3 and y=4 again x=5 x--== postdecrement x-1=4 y=x-- == y gets the value of x and x is postdecrement after that so that y stores 4 and not 3, what x will be after finish this line. print x=3 and y=4
20th Jul 2016, 10:03 AM
Steven
Steven - avatar
0
You should get a compile error when you run this
20th Jul 2016, 9:13 AM
chaitanya guruprasad
chaitanya guruprasad - avatar
0
actually, first, when you used x++ or ++x, then answer is always "x increase by 1".. eg; if x=2, then x++ or ++x=1+x =2+1 =3 or x++=x+1 =1+2 =3 both, ++x and x++ are equal...
20th Jul 2016, 2:10 PM
meherDev
meherDev - avatar
0
now see what I do... suppose y=++x, and =7; here you see the table phrases|int val of x|val of y|fnl val of x y=++x. x=5. 6. 6 y=x++. x=5. 5. 6 y=--x. x=5. 4. 4 y=x-- x=5. 5. 4 here int val means initial value of x, value of y and final value of x
20th Jul 2016, 2:15 PM
meherDev
meherDev - avatar