I l@ve RuBoard Previous Section Next Section

30.9 Final Note

Just when you think you've discovered all the things C++ can do to you—think again. There are still more surprises in store.

Question 30-1: Why does Example 30-1 think everything is two? (This inspired the final note.)

Example 30-1. not2/not2.cpp
#include <iostream>

int main(  )
{
    int number;

    std::cout << "Enter a number: ";

    std::cin >> number;

    if (number =! 2) 
        std::cout << "Number is not two\n";
    else
        std::cout << "Number is two\n";

    return (0);
}
    I l@ve RuBoard Previous Section Next Section