Data types in C

There are 5 basic data types defined in C

  1. int
  2. char
  3. float
  4. double
  5. void

Out of these only first 4 can be used to create variables. void cannot be used to create variables. It is only use to specify void return types from function or to create a void pointer.

int i;  // Correct

void v; // Incorrect

int Fun1()  // Correct
{
}

void Fun1() // Correct
{
}

Size of data types

The size of int , float and double may vary for different processors and compilers. But the size of char is always 1 byte no matter on which system you are working. Char variables are used to store the characters defined in the ASCII character set.

The size of float and double will depend on the method used to represent them.

Size of int is always equal to the word size of the processor. On a 16bit processor int is 16bit. On a 32 bit processor int is 32 bit.

Void is only used as return type for functions.

Signed , unsigned, long and short

You can modify the basic data types by using signed, unsigned, long and short keywords with them. You can use these modifiers to alter the meaning of any data type in order to fit it as per your needs.

Modifying char data type

You can only use unsigned and signed modifiers with char data type. It will affect the char data type as follows

Data Type Size in Bits Value range it can hold
char 8 -127 to 127
unsigned char 8 0 to 255
signed char 8 -127 to 127


Modifying the int data type

int data type can be modified in many ways. Following are the combination of modifiers you can use with int data type

Data type Size in bytes (On a 32 bit processor)  
int 4  
unsigned int 4  
signed int 4  
short int 2  
unsigned short int 2  
signed short int 2  
long int 4  
long long int 8  
signed long int 4  
unsigned long int 4  
unsigned long long int 8  

Modifying float

None of the modifiers can used with float data type

Modifying double

The only modifier you can use with double is long.

Important

When the type modifiers are used without any data type then int data type is assumed by default. For example

signed i ;      // Assumed as signed int i;
unsigned i;   // Assumed as unsigned int i;
long i;          // Assumed as long int i;
short i;        // Assumed as short int i;

Related Questions

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp