+ 1

Who can explain this question please?

What is is the output of this code? int x=0; x%=6; cout<<x; Answer=0

7th Jan 2023, 11:55 AM
Eeee
10 Respuestas
+ 4
x %= 6 is the same as: x = x % 6 Since modulo (%) looks at the remainder of a division, e.g. 4%2 = 0, because no remainder e.g. 5%2 = 1, because there is a remainder of 1 Applying this rule, we get this expression: 0%6 , which is 0/6. 0/6 is 0, therefore 0%6 = 0, because there are no remainders
7th Jan 2023, 12:06 PM
Lamron
Lamron - avatar
+ 3
Dinomath YT there is a little mistake in your answer that will be confusing to a beginner. 5%10 = 5 (not 0) because 5/10 = 0 with remainder 5. [Check: 0*10 + R5 = 5]
8th Jan 2023, 12:15 AM
Brian
Brian - avatar
+ 2
Brian sry, my mistake I typed wrong i was saying ( 10%5) and By dividing 10 to 5 we will got 2 and remainder 0.
8th Jan 2023, 7:23 AM
Dinomath YT
Dinomath YT - avatar
+ 1
modulo (%) looks at the remainder of a division, e.g. 5%2 = 1, because there is a remainder of 1 x %= 6 is the same as: x = x % 6 Applying this rule, we get this expression: Now, x = 0%6 The remainder of this equation is 0, therefore 0%6 = 0
9th Jan 2023, 4:13 AM
Asif Talukder
Asif Talukder - avatar
0
What don't you understand? The % (modulo) or cout<<x?
7th Jan 2023, 11:57 AM
Lamron
Lamron - avatar
0
How( 0%=6;) ?
7th Jan 2023, 12:01 PM
Eeee
0
0/6=0 is correct But why 0%6=0?
7th Jan 2023, 12:09 PM
Eeee
0
% modulo operator is doing a normal division to see if there is a remainder or not. Since we are doing 0/6 - we get 0, therefore there are no remainders ,
7th Jan 2023, 12:13 PM
Lamron
Lamron - avatar
0
The fundamental of (%)<--module: Module help to find reminders of any two numbers, e.g(5%10=by dividing 5 & 10,ans will be 2 and remainder will be 0) Just like in this case: (x%6) means 6 module with a variable and at last u puted the value of x=0, so that means ,0%6,if we divide it we will get 0 and remainder zero too , because dividing any number with zero provide remainder and quitient 0. I hope u understood ! :)
7th Jan 2023, 4:42 PM
Dinomath YT
Dinomath YT - avatar
0
in c and cpp modules to smaller value the answer is always smaller value i.e divide smaller by bigger value answer is always smaller one
9th Jan 2023, 11:02 AM
Amit Joe
Amit Joe - avatar