main () {
unsigned int x;
x = -1;
cout << "X is " << x << endl;
}
which produces
[bennett@douc54 three]$ g++ ints.cpp ints.cpp: In function `int main ()': ints.cpp:6: warning: assignment of negative value `-1' to `unsigned int' ints.cpp:6: warning: argument of negative value `-1' to `unsigned int' [bennett@douc54 three]$ a.out X is 4294967295
main () {
int foo;
foo = 010;
cout << "Foo is "<< foo << endl;
}
Will produce
Foo is 8
An bool is 1 bytes An char is 1 bytes An short is 2 bytes An int is 4 bytes An long is 4 bytes An float is 4 bytes An double is 8 bytes An long double is 12 bytes
main () {
int pow;
pow = 2;
cout << "Pow is " << pow << endl;
pow = pow * pow; // two squared
cout << "Pow is " << pow << endl;
pow = pow * pow; // two to the eighth
cout << "Pow is " << pow << endl;
pow = pow * pow; // two to the sixteenth
cout << "Pow is " << pow << endl;
pow = pow * pow; // two to the thirtysecond
cout << "Pow is " << pow << endl;
pow = pow * pow; // two to the 64
cout << "Pow is " << pow << endl;
}
Will produce
Pow is 2
Pow is 4
Pow is 16
Pow is 256
Pow is 65536
Pow is 0
int main () {
float x;
x = 1e3;
cout << x << endl;
}
Will produce
1000