0

how does this code works ?

I got this code: #include <iostream> using namespace std; int main() { int x,y=7; x=y=8; y=--x%y; cout<<y; return 8; } so in the third command first it decreases x so x now is 7 then assigns it to y so y is 7 then what next ?

9th May 2020, 4:29 PM
Sumer Fattoum
Sumer Fattoum - avatar
5 Antworten
+ 2
--x%y will first decrease the value of x from 8 to 7 then get the % modulus (remainder) of x/y. 8 goes into 7, 0 times leaving a remainder of 7. So 7 is returned and y = 7.
9th May 2020, 4:57 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
x and y both are equals value 8 the x is then decrease when --x%y so the value of x is 7 7%8 gives the remainer of 7.
11th May 2020, 10:02 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
you've re-assigned x and y to the value 8... the x is then pre-decremented so it's now 7.....so.. 7%8 gives the remainer of 7.
9th May 2020, 5:32 PM
rodwynnejones
rodwynnejones - avatar
0
thanks guys....my biggest Problem was if after the increment it assigns or does the remainder..now clear
9th May 2020, 5:50 PM
Sumer Fattoum
Sumer Fattoum - avatar
0
thanks guys....my biggest Problem was if after the increment it assigns or does the remainder..now clear
9th May 2020, 6:08 PM
Sumer Fattoum
Sumer Fattoum - avatar