Menu

Data Types in C

  • Data types determine the type of data a variable can hold. Data types are the means to identify the type of data and associated operations of handling it.
  • Example: if a variable 'x' is declared as 'int', the 'x' can hold only integer values.
  • Data types are divided into three,
    1. The system defined data types
    2. Derived data types
    3. User-defined data types

The system defined data types

  • System defined data types are the data types defined by the c compiler.
  • System defined data types can be divided as
    1. Numeric-integers, float
    2. character-single characters, string characters

Derived data types

  • These data types can be declared by the user by deriving the system-defined data type concepts.
  • Examples: Arrays, pointers.
  • Arrays: Collection of the same type of data referenced by a common name.
  • pointers: A variable that can hold the address of a memory location. The declaration of the pointer should consist of data type, an * (asterisk) and the variable name.

User-defined data types

  • These data types can be defined by the user.
  • Three types:
    1. Structures
    2. Unions
    3. Enumerations

Datatype modifiers

  • Type modifiers are the keyword used along with the basic data types to extend the range of data handled by the basic types.
  • The type modifiers of C are
    1. signed
    2. unsigned
    3. long
    4. short
Data type Memory
int 2
char 1
float 4
double 8
string size of the char array
unsigned int 2
long unsigned 8
long 4