Jan 10, 2016 at 9:14am UTC
What is the value of x after the following statements?
int x, y, z;
y = 10;
z = 3;
x = 3 + y * z;
output=====33
What is the value of x after the following statements?
int x;
x = 15 %4;
output====3
..thanks in advanced.................
Jan 10, 2016 at 10:40am UTC
What else do you expect from 15 % 3 (15 mod 3)? The remainder is 3.75 which is rounded down to 3 because the data type is an integer.
Jan 10, 2016 at 2:20pm UTC
The % operator gives you the remainder of the division.
https://en.wikipedia.org/wiki/Remainder
15 / 4 = 3 + 3 / 4
^ ^
| |
| 3 is the remainder of the division
| To get this value in C++ use 15 % 4
|
3 is the number of times that 4 divides 15
To get this value in C++ use 15 / 4
Last edited on Jan 10, 2016 at 2:22pm UTC
Jan 10, 2016 at 5:26pm UTC
Because variable x is the wrong data type.