Fundamental Types

C/C++ support most of the fundamental data types directly. The fundamental types are int, float, and char.
  1. int
    To store integer numbers.
    Eg: int i = 12;
    short
    Shortest integer representable. This is guaranteed to hold atleast the range -128 to 128.
    Eg: short i;
    long
    Gives extra precision than short.
    Eg: long i;
    unsigned
    Assumes integer is positive to enable storage of larger numbers. Eg:
    int i; // if i stores only the range -128 to 127
    unsigned i; // allows i to store the range 0 to 255.
  2. float
    To store floating point numbers.
    Eg: float i = 12.345;
    double
    Might give more (normally twice as much) precision than float.
    Eg: double i;
  3. char
    To store a single character.
    Eg: char ch = 'Z';

These types are further extended in the derived types, and by the use of structures, enumerated data types, and the typedef statement.

Look at the example from Hansen's answer book to see the differences between the data types. ( sizeof() is an operator to compare the storage sizes of types )

Exercises :

  1. Run the above example from the answer book and find out the differences between the data types in your machine under your compiler.
  2. What happens when you assign a floating point number to an integer ?

Please feel free to question or discuss any part of this section. These questions and discussions are also archived.
(C) 1994 naren
Distributed without any warranty under GNU GPL
nan2@cortex.eecs.lehigh.edu
Last modified: Thu Feb 9 20:06:11 1995