Home / Computer Science / C Language / Data types in C Language

Data types in C Language

Data types in C:

C has different types of data types. The data type is determines how much space is occupied by variable in the storage disk.

Mainly there are two types those are Pre- defined and User Defined.

Basic data types: These are arithmetic data types Integer, Char, float and Double.

Enumerated Type: enum is the arithmetic type used to define variables used to assign certain discrete integer values throughout the program.

Void data type: Void means no value.

Derived Data types: Derived data type means these are defined by the programmer at the time of programming based on the requirement.

Arrays, pointers, structures and union.

 

Data Types in C:

 

Data Types Size Range
Char 1 byte −128 to 127
signed char 1 byte −128 to 127
unsigned char 1 byte 0 to 127
Short 2 byte −32,768 to 32,767
signed short 2 byte −32,768 to 32,767
unsigned short 2 byte 0 to 32,767
Int 2 byte −32,768 to 32,767
signed int 2 byte −32,768 to 32,767
unsigned int 2 byte 0 to 32,767
short int 2 byte −32,768 to 32,767
signed short int 2 byte −32,768 to 32,767
unsigned short int 2 byte 0 to 32,767
long int 4 byte
signed long int 4 byte
unsigned long int 4 byte
Float 4 byte
Double 8 byte
long double 10 byte

 

The above shows the basic data types in c.

Note: If you want to know the exact size of the variable or a type use sizeof() operator .

Below program demonstrates how to use sizeof() operator in c and know the values of basic data types.

This is basic interview question for fresher use of sizeof() operator.

#include<stdio.h>

#include<conio.h>

void main(){

printf(“size of an integer: %d \n”,sizeof(int));

printf(“size of float: %d \n”,sizeof(float));

printf(“size of Character: %d \n”,sizeof(char));

printf(“size of double: %d \n”,sizeof(double));

getch();

}

 

Output is :

size of an integer:2

size of float: 4

size of Character:1

size of double: 8

Press  Alt +f9 and then Ctrl+f9 to compile and run the program.

 

Out put of the above program is:

 

About Santosh Kumar Gadagamma

I'm Santosh Gadagamma, an Experienced Software Engineer passionate about sharing knowledge in technologies like Java, C/C++, DBMS/RDBMS, Bootstrap, Big Data, Javascript, Android, Spring, Hibernate, Struts, and all levels of software design, development, deployment, and maintenance. I believe computers are essential for the world's functioning, and I'm committed to helping others learn the skills they need to succeed in tech. My website is a valuable learning tool to help you reach greater heights in your education and career, and I believe that education has no end points.

Check Also

Features of C language

WHERE is C Used Let us now see how does C compare with other programming …