What do the expressions in C++ return, the actual value obtained after applying the operators on the objects or true/false based on the calculated value ? Particularly :
In this code segment :
int i = 10, j = 5, k = 0;
i + j ;
k = i + j ;
while ( i + j )
{
// Do something worth for the universe in this time
}
What will the expression written in line No. 2 return, 15
or true
? Will it return the same value in line No. 4 ? Is 15
always returned, but converted to true
or false
based on the context ?
I read this in C++ Primer :
A while has the form
while (condition)
statement
A while executes by (alternately) testing the condition and executing the associated statement until the condition is false. A condition is an expression that yields a result that is either true or false.
But expressions could be just plain objects as well right !? How are they supposed to mean a true
or false
? For eg:
// Create an object `tempObject` of a class `SomeRandomClass`
while ( tempObject )
{
}
Can someone explain ?