C Data Types

Like any other programming language in C Programming Language “Variables” are one of the vital building block of any C Program. Variables are reserved memory locations to store values, when we create a variable we are a suppose to allocate some memory space for that variable.The C programming language is statically-typed, which means that all variables must first be declared before they can be used. This involves stating the variable’s data type and name of variable.

Example:

In C Programming Language every variable must have attached a data type to it, data type for a variable defines :

  • The amount of memory space allocated for variables.
  • A data type specifies the possible values for variables.
  • The operations that can be performed on variables.

In C Programming Language data types can be broadly classified as :

  • Primary data types – int, float, double, char, void
  • Derived data types – Derived from primitive data type ex: array, pointer,function etc.
  • User defined – Defined by the programmer himself.

Primary Data Types In C Language

The C Programming Language supports primary data types. A primary type is predefined by the language and is named by a reserved keyword.

Integer types:

Integers are whole numbers.int is used to define integer numbers.

Syntax:

 

Type Storage size Value range
int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295
short 2 bytes -32,768 to 32,767
unsigned short 2 bytes 0 to 65,535
long 4 bytes -2,147,483,648 to 2,147,483,647
unsigned long 4 bytes 0 to 4,294,967,295

Floating Point Types:

The float data type is used to store numbers with a decimal point(real number).

Syntax:

 

Type Storage size Value range Precision
float 4 byte 1.2E-38 to 3.4E+38 6 decimal places
double 8 byte 2.3E-308 to 1.7E+308 15 decimal places
long double 10 byte 3.4E-4932 to 1.1E+4932 19 decimal places

Character Type:

Used to define characters.Character type variable can hold a single character.

Syntax:

Type Storage size Value range
char 1 byte -128 to 127 or 0 to 255
unsigned char 1 byte 0 to 255
signed char 1 byte -128 to 127

Void Type:

The void type means no values. It can not be used with variable declaration.It is usually used with function to specify its return type or its arguments.

Example:

User defined type declaration

C Programming language allows users to create new data type. But it is usually created using existing data type with another identifier.This user defined data type identifier can later be used to declare variables. In short its purpose is to redefine the name of an existing data type.

Syntax:

Now we can use number identifier instead of int to declare integer variable.

Enum Data Type

This is an user defined data type having finite set of enumeration constants or aliases.

Syntax: