September 1998
Intermediate to advanced
848 pages
20h 13m
English
When you develop a program, note the variables you need and which type they should be. Most likely you can use int or possibly float for the numbers and char for the characters. Declare them at the beginning of the function that uses them. Choose a name for the variable that suggests its meaning. When you initialize a variable, match the constant type to the variable type.
int apples = 3; /* RIGHT */ int oranges = 3.0; /* WRONG */
C is more forgiving about type mismatches than, say, Pascal. C compilers allow the second initialization, but they might complain, particularly if you have activated a higher warning level. It is best not to develop sloppy habits.
When you initialize a variable of one numeric type to a value of ...
Read now
Unlock full access