Loading, please wait...

Variables

Declaring Data Variables 

In Call, variables are declared before they are used. This is so that:

  1. A memory location is given a name.
  2. A suitable number of bytes can be allocated.
  3. The compiler knows how to treat the data.

 

There are several data types in ‘C’:

 

Variable type

Number of bits

char

8

int

16 or 32 (usually)

short int

16           (usually)

short

16           (usually)

long int

32           (usually)

long

32           (usually)

float

About 32

double

About 64

long float

About64

long double

>64

 

  • The types short int and short are identical. Similarly long int and long are identical.
  • The char, int, short and long types can be preceded by the qualifiers signed or unsigned. The default is signed. If used on their own the type signed refers to type signed int and unsigned refers to type unsigned int.
  • The type char is so called as it is suitable for storing a character but the 'C' compiler will also let it be used to store numbers Corollary int, short or long variables, either signed or unsigned may be used for storing characters.
  • The number of bits for each type will vary from one compiler to the next, even on the same type of computer. The only thing guaranteed is that long it has more bits than short int, and double has more bits than float.
  • The number of bits for the type it is normally the most convenient size for the computer to handle. This can be the same as either type short int or long int or something in between. It is usually 16 or 32 bits.
  • The types long float, and long double is not available with all compilers.
  • the long float is often identical to double.