ch3-Bool in C++, permitted operations

Chapter_3     Exercise_3-5     Char sizeof     Exercise_3-6







Bool.cpp         download


#include <iostream>
using std::cout;
using std::endl;

int main()
{
bool b = false;

cout << "b = " << b << endl; // 0
cout << "++b = " << ++b << endl; // warning: deprecated, displays 1
cout << "++b = " << ++b << endl; // warning: deprecated, still 1
// cout << "--b = " << --b << endl; // compile error

b = 2; // no warning
cout << "b = " << b << endl; // still 1
b = -1; // no warning
cout << "b = " << b << endl; // still 1
cout << "++b = " << ++b << endl; // warning: deprecated, prints 1

return 0;
}
/*
g++ Bool.cpp -o Bool
./Bool
b = 0
++b = 1
++b = 1
b = 1
b = 1
++b = 1
*/





Note:  See also ch2-Types on the blog The_C++_Programming_Language, Chapter_2, Sec. 2.2.









Chapter_3     Exercise_3-5     Char BACK_TO_TOP sizeof     Exercise_3-6



Comments

Popular posts from this blog

Contents