Declaring Variables in C
Before you use a variable in a C program you must declare it. The tradition
in C is to declare all variables using lower case and to use the underscore as
the separator.
int num_of_hours;
float rate_of_pay;
- In C it is acceptable to declare more than one variable on the same line
double ytd_tot_gross, ytd_tot_fedwh,
ytd_tot_statewh;
- Variables may be declared as Global Variables or
Local variables. A Global variable is declared outside of any function and
is “known” to every function in the program. A variable declared in a
function is “known” only to that function.
- C does NOT assign an initial value automatically.
The programmer is responsible for placing a value in a variable. If no value
is assigned to the variable whatever value currently stored in the memory
allocated for that variable remains, no error is generated at compile or run
time. A variable may be initialized when it is declared.
double ytd_tot_gross = 0;