[prev] 55 [next]

Basic Data Types

  • In C each variable must have a type
  • C has the following generic data types:

    char   character   'A', 'e', '#', …
    int   integer   2, 17, -5, …
    float   floating-point number   3.14159, …
    double   double precision floating-point   3.14159265358979, …

  • Variable declaration must specify a data type and a name; they can be initialised when they are declared:

    float x;
    char  ch = 'A';
    int   j = i;
    

  • Value of a variable can be converted into a different type in expressions:

    int   m = 3, n = 4;
    float x;
    
    //   Type conversion
    x = (float)m / (float)n;
    // now, x = 0.75