Data is differentiated into various types. The type of a data element restricts the data element to assume a particular set of values. A data element of type int may only have integer values in the range -32767 to +32767. There are four fundamental C data types
| char | a character in the character set |
| int | a signed or unsigned number having no special characters |
| float | a signed or unsigned number having decimal point |
| double | a double-precision floating-point number |
The difference between floating point and double-precision numbers is how much storage a computer precision uses for each type. Most computers use twice the amount of storage for double for each data numbers type than for floating point numbers. However, the actual storage allocation depends on the particular computer. In amount of storage computers that use the same for double precision and become identical. The floating point numbers, these two data types sizeof operator can be used to determine the amount of reserved by the particular storage computer for each of these data types.
The qualifiers short and long can be applied to some of the above data types. Thus, the additional data types include
short int
long int
long double
Variables
There are two classes of data namely variables and constants. All data used in a computer program must be stored and retrieved from the computer's memory. Retrieving the data value for computations and storing them at different storage location in the memory is a cumbersome task. In C, symbolic names called variables are used in place of actual memory locations. A variable is an entity used by a program to store values used in the computation. Every variable in C has a type and it must be declared before it is used. The variable name should be selected in accordance with the following naming conventions.
Some legal and illegal C variable names:
| Variable Name | Legality |
| myName | Legal |
| xcWv__Egts | Legal |
| First_name | Legal |
| _myName | Legal but not advised |
| savings#account | Illegal: Contains the illegal character # |
| long | Illegal: Is a data type used to hold larger integer |
| 4sale | Illegal: First character is a digit |
Declaring a variable
A variable declaration consists of a data type name followed by a list of one or more variables of that type separated by commas. The declaration is done in the following format.
<data type> <variable name> ....;
The declarations are made generally at the beginning of the function. The definition
int a;
defines a memory location of size 4 bytes and of integer data type. Variables of the same type can be declared in the same line separated by commas as follows
int a, b, c;
Constants
A constant is an entity whose value does not change during program execution. Constants are of five different types: integer, floating-point, character, string and enumeration.
Integer
An integer constant is a number that has an integer value. Integer constants may be specified in decimal, octal or hexadecimal notation.
Floating point
A floating-point constant is a number that has a real value The standard decimal form of a floating-point constant is a number written with a decimal point Thus,
1.0 1 .1 0. .0
are valid floating-point constants. The following are not valid floating-point constants
1 Contains no decimal point
1,000.0 Contains a comma
1 000.0 Contains a space
Character
A character constant consists of a single character enclosed within apostrophes. '0 ' 'a' 'S' '+' etc... are valid character constants.
The value of the character constant is the numeric value of the character in the machine's character set and hence depends on whether the machine uses the ASCIl or EBCDIC character set.
String Constants
A string constant consists of zero or more characters enclosed within double quotation marks. Non-graphic characters may also be used as part of a character string. The following phrase
"All things bright and beautiful"
is an example for a string constant. The double quotation marks are not part of the string. They serve to delimit it. The length of the string is the number of characters that form the string. There is no limit on the length of the string. A string can be continued by putting a backslash () at the end of the line. The compiler automatically places the null character '" at the end of each string so that a program scanning a string can find its end. The physical storage is thus one byte more than the number of characters enclosed within double quotation marks.
Note
A character constant 'A' is not the same as the string that contains the single character "A". The former is the single character and the latter a character string consisting of characters A and .
Data types in C
| Variable Type | Keyword | Bytes Required | Range |
| Character | char | 1 | –128 to 127 |
| Short integer | short | 2 | –32767 to 32767 |
| Integer | Int | 4 | –2,147,483,647 to 2,147,438,647 |
| Long integer | Long | 4 | –2,147,483,647 to 2,147,438,647 |
| Long long integer | long long | 8 | –9,223,372,036,854,775,807 to 9,223,372,036,854,775,807 |
| Unsigned character | unsigned char | 1 | 0 to 255 |
| Unsigned short integer | unsigned short | 2 | 0 to 65535 |
| Unsigned integer | unsigned int | 4 | 0 to 4,294,967,295 |
| Unsigned long integer | unsigned long | 4 | 0 to 4,294,967,295 |
| Unsigned long long integer | unsigned long long | 8 | 0 to 18,446,744,073,709,551,615 |
| Single-precision floating-point | Float | 4 | 1.2E–38 to 3.4E381 |
| Double-precision floating-point | Double | 88 | 2.2E–308 to 1.8E3082 |
Note: