Lab 4 5 Confusing The Assignment Operator With Equality Test
Lab 4 5 Confusing The Assignment Operator With Equality Test
Objectives
In this lab, you distinguish the assignment operator from an equality operator in a Boolean
expression.
1. Write what the following statements display as output after the program executes:
int x = 8;
if (x == 10)
cout << “x is equal to 10\n”;
else
cout << “x is not equal to 10\n”;
2. The following code is the same as the code in Exercise 1 but uses the assignment operator
rather than the equality operator. Write what the following statements display as output after
the program executes:
int x = 8;
if (x = 10)
cout << “x is equal to 10\n”;
else
cout << “x is not equal to 10\n”;