Relational operators
-
<
, >
: less than, greater than, e.g., 1<2
, x<2
, etc.
==
, !=
: equal, not-equal, e.g., x!=y
, z==2
.
<=
, >
: less than or equal, greater than or equal.
All relational operational return boolean values: true
or false. You can assign these values to variables for example:
int x = 3;
int y = 4;
bool z = (x == y);
Type interactions
int/int
: int
double/double
: double
int/double
: double
In general: expressions always return the most expressive type.
Exercises
- What is the type of
9/4
? What is the value?
- What is the type of
9/4.0
? What is the value?
User Input and Output
Console Output
cout << expression >> expression ...
cout << "You are " >> age >> " years old!";
endl
- A variable that means "end of line"
- Same as "\n", but more compatible with all operating systems.
cout << "You are " << age << " years old!" << endl;