void fun()
{
bool a = true ;
bool b = true ;
bool x = a +b ; // a+b is 2, so x becomes true
bool y = a | b ; // a | bis 1, so y becomes true
}
A pointer can be implicitly converted to a bool. A nonzero pointer converts to true ; zerovalued pointers convert to false.
A type wchar_t is provided to hold characters of a larger character set such as Unicode.
A literal starting with zero followed by x (0x) is a hexadecimal (base 16)number. A literal starting with zero followed by a digit is an octal (base 8) number. For example:
decimal : 0 2 63 83
octal: 00 02 077 0123
hexadecimal: 0x0 0x2 0x3f 0x53
By default, a floating-point literal is of type double .
If you want a floating-point literal of type float, you can define one using the suffix f or F.
#include <iostream>
#include <limits>
using namespace std;
int main()
{
cout << "largest float == " << numeric_limits<float>::max()
<< ", char is signed == " << numeric_limits<char>::is_signed << endl;
cout << "specialized(char): " << numeric_limits<char>::is_specialized << endl;
}
If no initializer is specified, a global, namespace, or local static object (collectively called static objects) is initialized to 0 of the appropriate type. Local variables (sometimes called automatic objects) and objects created on the free store (sometimes called dynamic objects or heap objects) are not initialized by default.Members of arrays and structures are default initialized or not depending on whether the array or structure is static. Userdefined types may have default initialization defined.
Objects declared in global or namespace scope and statics declared in functions or classes are created and initialized once (only) and ‘‘live’’ until the program terminates.
Another use of a typedef is to limit the direct reference to a type to one place. For example:
typedef int int32;
typedef short int16;
If we now use int32 wherever we need a potentially large integer, we can port our program to a machine on which sizeof(int) is 2 by redefining the single occurrence of int in our code:
typedef long int32;