C Programming language

Data types in C
Previous Home Next

The C language supports a number of data types, all of which are necessary in writing programs. Because most CPUs generally support these data types directly, it is unnecessary for the compiler to convert the data types into the types the CPU understands. In addition to the standard types, new data types are needed, which are often unique to a given application, and C provides the mechanisms to create and use types of data created by the programmer.

Integer data type

Int 2 or 4 bytes Used for integer values.

Float data type

Float 4 bytes Floating-point numbers.

Char data type

char 1 byte Used for characters or integer variables.

Integers long and short

the range of an Integer constant depends upon the compiler. C offers a variation of the integer data type that provides what are called short and long integer values. Though not a rule, short and long integers would usually occupy two and four bytes respectively.

Each compiler can decide appropriate sizes depending on the operating system and hardware for which it is being written, subject to the following rules:

  1. shorts are at least 2 bytes big
  2. longs are at least 4 bytes big
  3. shorts are never bigger than ints
  4. ints are never bigger than longs

 

If there are such things as longs, symmetry requires shorts as well--integers that need less space in memory and thus help speed up program execution. short integer variables are declared as:

short int j ;
short int height ;

C allows the abbreviation of short int to short and of long int to long. So the declarations made above can be written as:

long i ;
long abc ;
short j ;
short height ;
Previous Home Next