// Ch. 7 Demo Program #1 // Mr. Minich
#include<iostream.h> int main() { int num1 = 0;
// used in expressions that illustrate the use of assigment and logical and relational expressions cout << "num1 equals " << num1 << endl;
// This prints "num1 equals 0" cout << "num1 equals " << (num1 = 3) << endl;
// This prints "num1 equals 3" because C++ performs the assignment of the value 3 // to the variable num1 and prints its value. This line of code could easily be // split over 2 lines of code of course such as, // num1 = 3; // cout << "num1 equals " << num1 << endl; cout << "num1 equals " << (num1 == 3) << endl;
// This prints "num1 equals 1" because the result of the expression (num1 == 3) // is TRUE, which is equivalent to the value of 1 according to C++. The double // equals (==) is a relational operator, NOT the C++ assignment operator. cout << "num1 equals " << (num1 != 3) << endl;
// This prints "num1 equals 0" since the relational expression evaluates to FALSE, // which is equivalent to the value of 0 according to C++. return 0; }// end of main