Huge pointer in c programming
Huge pointer:
The pointer which can point or access whole the
residence memory of RAM i.e. which can access all the 16 segments is known as
huge pointer.
Size of huge pointer is 4 byte or 32 bit.
(1)What will be output of following c program?
#include<stdio.h>
#include<stdio.h>
int main(){
char huge * far *p;
printf("%d %d %d",sizeof(p),sizeof(*p),sizeof(**p));
return 0;
return 0;
}
Output: 4 4 1
Explanation: p is huge pointer, *p
is far pointer and **p is char type data variable.
Normalization of huge pointer:
Turbo C compiler is based on 8085 microprocessor in which
physical address of memory is represented in 20 bit. Conversion of 4 byte or 32
bit huge address into 20 bit actual physical address is known as normalization.
Formula to calculate physical address:
Example:
(q) What will be physical address of huge address 0X59994444?
Answer:
Huge address: 0X59994444
Offset address: 0x4444
Segment address: 0x5999
Physical address= Segment address * 0X10 +
Offset address
=0X5999 * 0X10 +0X4444
=0X59990 + 0X4444
=0X5DDD4
In binary: 0101 1101 1101 1101 0100
Note: Each hexadecimal digit
is represented in 4 bit binary number.
When any relation operation is performed between two huge
pointers first it normalizes in actual physical address.
Example:
(q)What will be output of following c program?
#include<stdio.h>
#include<stdio.h>
int main(){
int huge*p=(int huge*)0XC0563331;
int huge*q=(int huge*)0xC2551341;
if(p==q)
printf("Equql");
else
printf("Not equal");
return 0;
}
}
Output: Equal
Explanation:
As we know huge pointers compare its physical address.
Physical address of huge pointer p
Huge address: 0XC0563331
Offset address: 0x3331
Segment address: 0XC056
Physical address= Segment address * 0X10 +
Offset address
=0XC056 * 0X10 +0X3331
=0XC0560 + 0X3331
=0XC3891
Physical address of huge pointer q
Huge address: 0XC2551341
Offset address: 0x1341
Segment address: 0XC255
Physical address= Segment address * 0X10 +
Offset address
=0XC255 * 0X10 +0X1341
=0XC2550 + 0X1341
=0XC3891
Since both huge pointers p and q are pointing same physical
address so if condition will true.
(q)What will be output of following c program?
#include<stdio.h>
#include<stdio.h>
int main(){
double near *p,far *q;
printf("%d %d %d",sizeof(q),sizeof(p),sizeof(*p));
return 0;
return 0;
}
Output: 4 2 8
Explanation: q is far pointer, p is
near pointer, *p is double data type constant.
Don’t use huge pointer:
If you will increment huge pointer it will increment both offset
and segment address unlike to far pointer which only increments offset address.
So if you have little knowledge about huge pointer and you are using huge
pointer then you can easily access and modify the IVT, device driver memory,
video memory etc. This might be dangerous for your computer.
(q)Why there are three types of pointer in Turbo c compiler?
Answer:
Turbo c compiler is based on Dos operating
system which is based on 8085 microprocessors. In 8085 microprocessor actual
physical address is represented in 20 bit. But there are not any pointers which
can point 20 bit address. Considering simplicity of calculations, access to
actual physical address, security etc. c has introduced three type of pointer
i.e. near, far and huge pointer.
No comments:
Post a Comment