Proper Variable Syntax

The overwhelming majority of data you'll work with will be in the form of variables (as opposed to constants, which you'll also learn about at the end of this chapter). To use a variable, you must first declare it—in other words, you state that a variable with a specific name will be of a certain type. The declaration statement looks like this:

					datatype variablename;

For example:

int age;
float cost;
char answer;

The different types are listed in Table 2.1, along with what version of C they are allowed in.

Table 2.1. The basic variable types for use in the C language and what standard they fall under.
C Data Types
TypeC Standard
intAll
long intAll
long long intAll
short intAll
unsignedAll
floatAll
doubleAll
long doubleAll
char ...

Get C Programming: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.