Declaring Variables

All variables must be declared prior to use. Here is the general form of a declaration:

type variable_name;

For example, to declare x to be a float, y to be an integer, and ch to be a character, you would write

float x; int y; char ch;

You can declare more than one variable of a type by using a comma-separated list. For example, the following statement declares three integers:

int a, b, c;

Initializing Variables

A variable can be initialized by following its name with an equal sign and an initial value. For example, this declaration assigns count an initial value of 100:

int count = 100;

An initializer can be any expression that is valid when the variable is declared. This includes other variables and function calls. However, in C, global variables and static local variables must be initialized using only constant expressions.




C(s)C++ Programmer's Reference
C Programming on the IBM PC (C Programmers Reference Guide Series)
ISBN: 0673462897
EAN: 2147483647
Year: 2002
Pages: 539

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net