+ 1
What does it do?
what does this line of code do in c++?can you please explain IN DETAIL cout<<Remainder < 0 ? Remainder+(Base*-1) :Remainder; //Remainder and Base are defined variables...this is a base convertor code.
1 Answer
+ 1
Remainder < 0 ? Remainder+(Base*-1) : Remainder
This works almost like a if-else statement.
a ? b : c;
is like writing
if(a){
b;
} else {
c;
}
(just that you can't use if-else like this within a cout)
So if Remainder < 0 is true then it will cout << Remainder+(Base*-1);
If Remainder < 0 is false it will cout << Remainder;