October 2004
Beginner
408 pages
9h 24m
English
Once you've declared a variable, you can initialize it, which means giving that variable a value. Assigning values to simple variables like numbers is very easy and requires only the assignment operator (=):
int model_year; model_year = 2004; float cost; cost = 1.95;
Although you must declare a variable before assigning a value to it, C does allow you to perform both acts in one step:
int model_year = 2004; float cost = 1.95
Let's build on the previous example by assigning values to the declared variables.
1. | Open var1.c (Script 2.1) in your text editor or IDE. |
2. | After declaring the variables but before the return statement, assign each variable a value (Script 2.2):
age = 40; ... |
Read now
Unlock full access