C Language



Admission Enquiry Form

  

Data Types in C




Data Types in C

Here, we will learn about the data types in C such as int, char, float,double etc.
In C data types are used to declare variables.Data types determine the size and type of value which is associated with a variable.For example:

int num1;
float num2;
char ch;

Here, num1 is a variable of int (integer) type. The size of int is at least 2, usually 4 bytes,depends upon 32 bits or 64 bits compiler.
num2 is a variable of float type. The size of float is 4 bytes.
ch is a variable of char (character) type. The size of char is 1 byte.

We can check the size of a variable using sizeof() opeartor.




Example 1

#include<stdio.h>
#include<conio.h>
void main()
{
int num1=10;
float num2=20.45;
char ch='C';
printf("Value of num1 is %d and size of num1 is %d",num1,sizeof(num1));
printf("\nValue of num2 is %f and size of num2 is %d",num2,sizeof(num2));
printf("\nValue of ch is %c and size of ch is %d",ch,sizeof(ch));
getch();
}//end of main


Output

Value of num1 is 10 and size of num1 is 4
Value of num2 is 20.450001 and size of num2 is 4
Value of ch is C and size of ch is 1



Integer Data Type

Integers are used to store whole numbers.

Size and range of Integer type on 32-bit compiler:

Data Type Size(Bytes) Format Specifier Range
short int 

-32,768 to 32,767 
%hd 
unsigned short int 

0 to 65,535 
%hu 
unsigned int 

0 to 4,294,967,295 
%u 
int 

-2,147,483,648 to 2,147,483,647 
%d 
long int 

-2,147,483,648 to 2,147,483,647 
%ld 
unsigned long int 

0 to 4,294,967,295 
%lu 



Character Data Type

Character types are used to store character values.

Size and range of Character type on 32-bit compiler:

Data Type Size(Bytes) Format Specifier Range
signed char 

-128 to 127 
%c 
unsigned char 

0 to 255 
%c 



Float Data Type

Float types are used to store decimals or real numbers.

Size and range of Float type on 32-bit compiler:

Data Type Size(Bytes) Format Specifier Range
float 

 3.4E-38 TO 3.4E+38 %f 
double 

 1.7E-308 TO 1.7E+308 %lf 
long double 
16 
 3.4E-4932 TO 1.1E+4932 %Lf 



Void Type

void type means "no type"or "nothing".It does not store any value.void type is used in functions to specify that function is returning nothing. We can not declare a variable of type void.We will learn this datatype in advanced topics in C programming, like pointers,functions etc.