- 1
What do % and (a>b)? a:b mean?
So the first question is: what is %? Ex: a%b The 2nd question is: I know what (a>b)? Means but what is a:b??? Thanks...
4 Answers
+ 4
A%B = X:
5%2 = 1;
% stands for the modulus operator, what it basically does, is give you the remainder of division between A and B.
std::string exampleVariable = (true) ? "Cool, it's true." : "Aww, it's false";
This syntax expanded is:
std::string exampleVariable;
if (true) {
exampleVariable = "Cool, it's true.";
} else {
exampleVariable = "Aww, it's false.";
}
So, basically the value on the left side of the " : ", is the value that will be represented if the boolean is true.
+ 1
5 % (modulo) 3 is 2 because it's one with a rest of 2.
8 % 4 = 0
12 % 7 = 5
100 % 3 = 1
x = (condition) ? a : b;
is the same as
if (condition) x = a;
else x = b;
0
Thank you!
- 1
No problem. Please mark your question as solved to save other users time. ( :