Tuesday, September 21, 2010

Variable Initializations in C and C++

You can give variables a value as you declare them by placing an equal sign and a
value after the variable name. The general form of initialization is
type variable_name = value;
Some examples are
char ch = 'a';
int first = 0;
float balance = 123.23;
Global and static local variables are initialized only at the start of the program. Local
variables (excluding static local variables) are initialized each time the block in which
they are declared is entered. Local variables that are not initialized have unknown
values before the first assignment is made to them. Uninitialized global and static local
variables are automatically set to zero.

No comments:

Post a Comment