Data Types

Data types define how much storage space a variable is going to take. The C programming language provides roughly 3 categories of data types.

  1. Basic data types: int, float, double, char, and _Bool.
  2. Derived data types : array, structure, union, function, etc.
  3. void type : void

The Basic Integer Type : int

In C, an integer constant consists of a sequence of one or more digits. A minus sign preceding the sequence indicates that the value is negative.The values 158, –10, and 0 are all valid examples of integer constants.

Octal Format : If the first digit of the integer value is a 0, the integer is taken as expressed in octal notation—that is, in base 8. In that case, the remaining digits of the value must be valid base-8 digits and, therefore, must be 0–7. So, to express the value 50 in base 8 in C, which is equivalent to the value 40 in decimal, the notation 050 is used.

Hexadecimal Format : If an integer constant is preceded by a zero and the letter x (either lowercase or uppercase), the value is taken as being expressed in hexadecimal (base 16) notation. Immediately following the letter x are the digits of the hexadecimal value, which can be composed of the digits 0–9 and the letters a–f (or A–F). The letters represent the values 10–15, respectively.

Storage Sizes and Ranges

The size of integer type depends on the data model of the platform. If you want to learn more about data models, <visit this page>. As of now lets assume the following holds good for the gcc compiler on linux.

 

TYPE

SIZE RANGE

int

4 bytes -2,147,483,648 to 2,147,483,647

unsigned int

4 bytes

0 to 4,294,967,295

short

2 bytes

-32,768 to 32,767

unsigned short

2 bytes

0 to 65,535

long

4 bytes

-2,147,483,648 to 2,147,483,647

unsigned long 4 bytes

0 to 4,294,967,295

Continued on next page . . .

You may also like...