Initializers
Declaration and initialization may be done in one statement instead of in two separate statements.
Int amt; //declare
amt = 3; //initialize
This is shorter:
int amt = 3; //looks like an assignment statement but is not.
And this may also be used *:
Int amt(3); //available in C++ but not in C
Any expression may be used for the initialization, subject to the restrictions below.
It is important to realize that the initialization of the variable takes place each time its parent block is executed (with the exception of static variables – they are initialized only once).
Restriction on Global and Static Variables:
The expression used to initialize a Global or Static Variable must be a constant – i.e., it may not contain function calls, references to non-const variables or increment/decrement operators.
* Some programmers prefer to use the C format with the equal sign, because it is more obvious as to what is being done. The use of parens in the C++ format reflects the influence of the notation used in initializing class objects that have constructors.