Thursday, December 25, 2008

Far pointer in C Programming Questions with Answers

Q1. What will be output ?
void main()
{
char far *p=(char far *)0x55550005;
char far *q=(char far *)0x53332225;
clrscr();
*p=25;
(*p)++;
printf("%d",*q);
getch();
}
Output: 26
Explanation:
Far address of p and q are representing same physical address .
Physical address of 0x55550005= 0x5555*ox10+ox0005= 0x55555
Physical address of 0x53332225=0x5333*0x10+ox2225=0x55555
*p =25, means content at memory location 0x55555 is assigning value 25
(*p)++ means increase the content by one at memory location 0x5555 so
now content at memory location 0x55555 is 26
*q also means content at memory location 0x55555 which is 26

Q2. what will be output ?

#include
void main()
{
unsigned int i,offset_addr,seg_addr,;
char far *ptr=(char far *) 5555 FF99;
for (i=0;i<300;i++)
{
seg_addr=FP_SEG(p);
offset_addr=FP_OFF(p);
printf(“\n seg_addr %x offset_addr %x ”,seg_addr,offset_addr);
p++;
delay(100);
}
}

No comments:

Blog List