The pointer which can point or access whole the residence memory of RAM i.e. which can access all 16 segments is known as far pointer.
Size of far pointer is 4 byte or 32 bit. Examples:
(1) What will be output of following c program?
int main(){
int x=10;
int far *ptr;
ptr=&x;
printf("%d",sizeof ptr);
return 0;
}
Output: 4
(2)What will be output of following c program?
int main(){
int far *near*ptr;
printf("%d %d",sizeof(ptr) ,sizeof(*ptr));
return 0;
}
Output: 4 2
Explanation: ptr is far pointer while *ptr is near pointer.
(3)What will be output of following c program?
int main(){
int far *p,far *q;
printf("%d %d",sizeof(p) ,sizeof(q));
}
Output: 4 4
First 16 bit stores: Segment number
Next 16 bit stores: Offset address
Example:
int main(){
int x=100;
int far *ptr;
ptr=&x;
printf("%Fp",ptr);
return 0;
}
Output: 8FD8:FFF4
Here 8FD8 is segment address and FFF4 is offset address in hexadecimal number format.
Note: %Fp is used for print offset and segment address of pointer in printf function in hexadecimal number format.
In the header file dos.h there are three macro functions to get the offset address and segment address from far pointer and vice versa.
1. FP_OFF(): To get offset address from far address.
2. FP_SEG(): To get segment address from far address.
3. MK_FP(): To make far address from segment and offset address.
Examples:
(1)What will be output of following c program?
#include "dos.h"
int main(){
int i=25;
int far*ptr=&i;
printf("%X %X",FP_SEG(ptr),FP_OFF(ptr));
}
Output: Any segment and offset address in hexadecimal number format respectively.
(2)What will be output of following c program?
#include "dos.h"
int main(){
int i=25;
int far*ptr=&i;
unsigned int s,o;
s=FP_SEG(ptr);
o=FP_OFF(ptr);
printf("%Fp",MK_FP(s,o));
return 0;
}
Output: 8FD9:FFF4 (Assume)
Note: We cannot guess what will be offset address; segment address and far address of any far pointer .These address are decided by operating system.
Limitation of far pointer:
We cannot change or modify the segment address of given far address by applying any arithmetic operation on it. That is by using arithmetic operator we cannot jump from one segment to other segment. If you will increment the far address beyond the maximum value of its offset address instead of incrementing segment address it will repeat its offset address in cyclic order.
Example:
(q)What will be output of following c program?
int main(){
int i;
char far *ptr=(char *)0xB800FFFA;
for(i=0;i<=10;i++){
printf("%Fp \n",ptr);
ptr++;
}
return 0;
}
Output:
B800:FFFA
B800:FFFB
B800:FFFC
B800:FFFD
B800:FFFE
B800:FFFF
B800:0000
B800:0001
B800:0002
B800:0003
B800:0004
This property of far pointer is called cyclic nature of far pointer within same segment.
Important points about far pointer:
1. Far pointer compares both offset address and segment address with relational operators.
Examples:
(1)What will be output of following c program?
int main(){
int far *p=(int *)0X70230000;
int far *q=(int *)0XB0210000;
if(p==q)
printf("Both pointers are equal");
else
printf("Both pointers are not equal");
return 0;
}
Output: Both pointers are not equal
(2)What will be output of following c program?
int main(){
int far *p=(int *)0X70230000;
int far *q=(int *)0XB0210000;
int near *x,near*y;
x=(int near *)p;
y=(int near *)q;
if(x==y)
printf("Both pointer are equal");
else
printf("Both pointer are not equal");
return 0;
}
Output: Both pointers are equal
2. Far pointer doesn’t normalize.
233 comments:
«Oldest ‹Older 201 – 233 of 233Very good explanation (even these things are not really "basic".
For Q.17-(4), I think there is a mistake.
int ( * ( * ptr ) [ 5 ] ) ( )
Your Answer:
ptr is a pointer to such array of size five which content are pointers to
such function which parameter is void and return type is int type data.
Should be:
ptr is a pointer to such array of size five which content are pointers to
such function which has undefined (variable) number of parameters and return type
is int type data.
Since : int Foo () is a function which takes an undefined (variable) number of
parameters. That is totally different from int Foo (void) which takes no parameter
and return type is int.
Nice Explanation....Very useful for interviews
int main(){
int num,i=0;
do{
printf("To enter press 1\n");
printf("To exit press 2");
scanf("%d",&num);
++i;
switch(num){
case 1:printf("You are welcome\n");break;
default : exit(0);
}
}
while(i<=10);
return 0;
}
Output: 3 3 4 4
question no 8
how come output is this??
this is wrong
we r not printing any value
Programming in c by Stephen kochain and expert in c
You can also refer numerical recipes inc
Nice site and nice ques
Plz upload some more questions
wow.......this is helpfull blog.....
Nice tutorial. Thanks for sharing the valuable info about c Training. it’s really helpful. Who want to learn c language this blog most helpful. Keep sharing on updated tutorials…..
I can't understand the meaning for third questions answer.Can u please explain me....?
It's great job and more useful to others
Hello there!
I'm Simran from Receptix - a job search portal. I stumbled on your website and I must say it envelopes great information.
Coincidentally, we have a video designed on a topic similar to your blog post on interview questions on C language. I was wondering that incorporating this video can further enhance the user experience on your page. Here's the link to the video
https://www.youtube.com/watch?v=WPnURgypr9U
It will be great if you could also mention www.receptix.com as the source, along with the video.
Look forward to this content synergy.
Thanks
Thank for this blog are more informative step by step and useful contents. I here by attached my site would you see this blog
7 tips to start a career in digital marketing
“Digital marketing is the marketing of product or service using digital technologies, mainly on the Internet, but also including mobile phones, display advertising, and any other digital medium”. This is the definition that you would get when you search for the term “Digital marketing” in google. Let’s give out a simpler explanation by saying, “the form of marketing, using the internet and technologies like phones, computer etc”.
we have offered to the advanced syllabus course digital marketing for available join now
more details click the link now
https://www.webdschool.com/web-development-course-in-chennai.html
Amazing blog useful information
Web designing trends in 2020
When we look into the trends, everything which is ruling today’s world was once a start up and slowly begun getting into. But Now they have literally transformed our lives on a tremendous note. To name a few, Facebook, Whats App, Twitter can be a promising proof for such a transformation and have a true impact on the digital world.
we have offered to the advanced syllabus course web design and development for available join now
more details click the link now
https://www.webdschool.com/web-development-course-in-chennai.html
Great good questions keep it up
Learnprogramo.
Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites! 360DigiTMG PMP Certification
PMP Certification in Malaysia
PMP Course
PMP Course in Malaysia
I am impressed by the information that you have on this blog. It shows how well you understand this subject.
data analytics course
big data analytics malaysia
big data course
Great Article it its really informative and innovative keep us posted with new updates. its was really valuable. thanks a lot.
data science course
I was just browsing through the internet looking for some information and came across your blog. I am impressed by the information that you have on this blog. It shows how well you understand this subject. Bookmarked this page, will come back for more.
360DigiTMG PMP Certification
360DigiTMG PMP Course in malaysia
360DigiTMG PMP Course
360DigiTMG PMP Training in malaysia
360DigiTMG PMP Training
The blog and data is excellent and informative as welldata science course
Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!
data analytics course
big data analytics malaysia
big data course
It was a great information and Its really worth reading it.
Online Training
software training institute
online classes
Thanks for sharing such a great blog
python training in bangalore | python online Training
artificial intelligence training in bangalore | artificial intelligence online training
machine learning training in bangalore | machine learning online training
uipath-training-in-bangalore | uipath online training
blockchain training in bangalore | blockchain online training
aws training in Bangalore | aws online training
data science training in bangalore | data science online training
hadoop training in bangalore | hadoop online training
iot training in bangalore | iot online training
devops training in banaglore | devops online training
Nice Information Your first-class knowledge of this great job can become a suitable foundation for these people. I did some research on the subject and found that almost everyone will agree with your blog.
Cyber Security Course in Bangalore
Writing in style and getting good compliments on the article is hard enough, to be honest, but you did it so calmly and with such a great feeling and got the job done. This item is owned with style and I give it a nice compliment. Better!
Cyber Security Training in Bangalore
Top quality blog with unique content and found valuable looking forward for next updated thank you
Ethical Hacking Course in Bangalore
Amazing blog with unique information found valuable and enjoyed reading this one. Keep posting. Thanks for sharing.
Data Science Training in Hyderabad
I finally found a great article here. I just added your blog to my bookmarking sites looking forward for next blog thank you.
Data Science Course in Bangalore
I recently found a lot of useful information on your website, especially on this blog page. Among the many comments on your articles. Thanks for sharing.
Business Analytics Course in Bangalore
This is an excellent article. I like this topic. This site has many advantages. I have found a lot of interesting things on this site. It helps me in so many ways. Thanks for posting this again.
Data Analytics Course in Bangalore
Thanks, this is generally helpful.
Still, I followed step-by-step your method in this Python Online Training
Python Online Course
Fantastic blog with excellent information and valuable content just added your blog to my bookmarking sites thank for sharing.
Data Science Course in Chennai
Thanks for sharing. It is very useful article;please visit us at our website :
http://www.univ-msila.dz/en
I really enjoy every part and have bookmarked you to see the new things you post. Well done for this excellent article. Please keep this work of the same quality.
Artificial Intelligence course in Chennai
Post a Comment