Memory representation of int data type in C


Memory representation of int data type in c programming language

int may be signed or unsigned both have different memory representation.

1. Memory representation of:

unsigned int a=7;

It is 16-bit data type and all 16 bit is data bit.
Binary equivalent of 7 is: 111
for 16 bit we will add 13 zero in the left side i.e. 00000000 00000111
Since Turbo C is based on 8085 microprocessor which follow little-endian.
Here A is 00000111 and B is 00000000

Memory representation: 
Note: same memory representation will be of:

unsigned short int a=7;

2. Memory representation of:
 
int a=7 or signed int a=7;
 
It is 16 bit data type.
15 bit: data bit
1 bit: signed bit
Binary equivalent of 7 is 111
for 16 bit we will add 13 zero in the left side i.e. 00000000 00000111
Here
A is 00000111
B is 00000000


Memory representation:

Note: same memory representation will be of:


3. Memory representation of:

int a= -7 or signed int a= -7;
It is 16 bit data type. Binary equivalent of 7 is 111 for 16 bit we will add 13 zero in the left side i.e. 00000000 00000111 since a is negative number so it will first convert in the 2’s complement format before stored in the memory. 1’s Complement of a: 11111111 11111000 + 1 ______________________ 2’s Complement of a: 11111111 11111001 Memory representation

Note: same memory representation will be of:
short int a=-7 or signed short int a=-7;

5 comments:

Naresh @IITD said...

Is it same in GCC ?

Sandeep Singh Sengar said...

nice tute

Unknown said...

so usefull

Anonymous said...

satya ki ma ka bhosda

Unknown said...

What about memory representation of
unsigned int a = -1;