C Data Types
In this tutorial, you will learn about basic data types in C programming such as int, float, char etc.
Data types specify how we enter data into our programs and what type of data we enter. C language has some predefined set of data types to handle various kinds of data that we can use in our program. These datatypes have different storage capacities.
C language supports 2 different type of data types:
- Primary data types:
These are fundamental data types in C namely integer(
int), floating point(
- Derived data types:
Derived data types are nothing but primary datatypes but a little twisted or grouped together like array, stucture, union and pointers. These are discussed in details later.
Data type determines the type of data a variable will hold. If a variable
x is declared as
int. it means x can hold only integer values. Every variable which is used in the program must be declared as what data-type it is.
Data types are used to identify the size of variable and type of datastored in it.
In the above example, we have declare a variable points of
int int type.
There are four types of datatypes in C programming :
- Basic data types : int, float, double and char
- Enumeration data type : enum
- Derived data type : pointer, array, structure and union
- Void data type : void
Basic Data types
These are the basic datatypes in C programming :
|Type||Size (bytes)||Format Specifier||Range|
||2 or 4||
||-32,768 to 32,767 or -2,147,483,648 to 2,147,483,647|
||-128 to 127 or 0 to 255|
||-32,768 to 32,767|
||2 or 4||
||0 to 65,535|
||4 or 8||
||-2,147,483,648 to 2,147,483,647|
||-263 to 263-1|
||at least 4||
||0 to 4,294,967,295|
||at least 8||
||0 to 18,446,744,073,709,551,615|
||-128 to 127|
||0 to 255|
||at least 10, usually 12 or 16||
Int datatype is used to store an integer.
We have to use
int keyword for declaring an integers (whole number both positive and negative including 0) before variable name.
In the above example, marks is a variable of int type.
We can also declare multiple variables of same type at once in C programming.
int city_code, area_code;
The size of
int is range from 2 bytes (16 bits) to 4 bytes (32 bits). And, it can take
232 distinct states from
Note : If you want to store the integer value that crosses the above limit for
int, then use “long int” and “long long int” to store the integer value.
float and double
Float datatype is used to store decimal numbers with single precision where as Double datatype is used to store double precision.
We have to use float keyword to declare a
float type variable and double keyword to declare a
double type variable.
In C programming, floating-point numbers can also be represented in exponential.
float expo-number = 22.235d1;
What’s the difference between
double are used to store floating-point number but the size of
float is 4 bytes and the size of
double is 8 bytes.
Char datatype is used to store a single character within a single quotation.
We have to use char keyword to declare a character datatype.
char datatype use 1 byte memory to store a single character.
char grade = 'B';
Note : It is necessary to write character inside the single quote.
Note : To increase the size of any of the basic datatype except char we have to use long and long long before datatype.
To decrease the size of the any of the basic datatype except char , we have to use short keyword before datatype.
signed and unsigned
signed and unsigned are type modifiers in which signed datatype can store 0, positive or negative values. unsigned datatype can only store 0 or positive value.
unsigned int a;
In the above example, the variable a can store only zero or positive values because we have used the
unsigned modifier. The variable b can store zero, positive values or negative values because the datatypes are already modified as signed by default.
Note : The size of the unsigned datatypes are always greater than signed datatype.
Note : We cannot create variables of void type.
Void means “nothing” or “no-type” i.e. It is an empty datatype that has no value and can be used in functions and pointers.
We can assume void as absent.
Note : void is mainly used to represent the function when it is not returning anything.