position: fixed; top: auto !important; margin-left: 112px;

Data Types in C

void main( ) 
    {
    int a = 1; 
    printf("%d ,a");
    }
    

What happens in memory when you write

int a = 1;

Compiler will tell itself, Hey there is request for me to store variable a with value 1 and it is a integer. So ,‘a’ as a variable with value ‘1’ and since it is integer , memory of 2 or 4 bytes will be created for it.

Pictorial view will be like this ,

Address Value Stored Indicated by variable
100 ....
104 1 a
108 ....
112 ...

In this diagram , value 1 is stored at 104 address of memory and it is represented by variable a. This is how you can read a = 1. And since variable a was integer, address in memory was incremented by 4 bytes i.e 100, 104,108,112 etc.

If variable was double value like this,

double a = 2.1;

then address in memory were incremented by 8 bytes i.e 100, 108 , 116 etc.

What are Datatypes in C ?

Each variable in C is associated with one datatype like int, float , double , char etc. depending on which memory is created for that variable . Compiler should know how much memory it should reserve for the variable which is requesting to store some value in its storage.

Types of Datatypes in C

C Datatypes are divided into four types :-

1) Basic Datatypes

2) Derived Datatypes

3) Ennumeration Datatype

4) void Datatype

Sr. NoDatatypesDatatype Description
1) Basic Data Type int, char, float, double
2) Derived Data Type Array, Pointer, Structure, Union
3) Enumeration Data Type enum
4) void void return nothing.

Basic Datatypes in C

Size of C datatypes may vary according to 32 or 64 bit Architecture. Its size is given according to 32 bit architecture.:-

C Datatype Size Range
char 1 byte -128 to 127
signed char 1 byte -128 to 127
unsigned char 1 byte -128 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 65,535
int 2 byte(32-bit) & 4 byte(64-bit) -32,768 to 32,767
signed int 2 byte(32-bit) & 4 byte(64-bit) -32,768 to 32,767
unsigned int 2 byte 0 to 65,535
short int 2 byte -32,768 to 32,767
long int 4 byte -2,147,483,648 to 2,147,483,647
signed long int 4 byte -2,147,483,648 to 2,147,483,647
unsigned long int 4 byte 0 to 4,294,967,295
float 4 byte 1.2E-38 to 3.4E+38
double 8 byte 2.3E-308 to 1.7E+308
long double 10 byte 3.4E-4932 to 1.1E+4932

Solve the Quiz of Article

1) The format identifier ‘%i’ is also used for int data type?
Yes
No

2) Is size of double datatype is 4 bytes?
Yes
No


Previous Next Article







codzify.com


Largest collection of up-to-date tutorials to learn programming languages. We are focused on easy learning. Massive collection of interview questions one may need for preparation.

Social Profile


Linkedin
Twitter
Facebook

Copyright 2018. All rights reserved.