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.
72 comments:
great job!!
Consider the input file as follow:
1111 2050.00 20
1234 1890.50 30
1654 1769.40 40
…….
1972 2180.90 10
The above input contains the data of employees’ monthly salary for xyz company.
The first data in a line is staff ID, followed by basic salary and then total over time working hours. The input file name is input.txt.
The total salary of each staff is calculated by adding basic salary with over time salary. The rate of over time work is RM 5 per hour.
Write a complete program to retrieve the data from the input.txt file, calculate the total salary for each staff in the month, and output the staffs’ IDs and their total salaries into a file named output. Txt. The program should also be able to allow the user to print the salary details of a specific staff by entering the particular staff ID. The program must have the following functions:
Function name description
writeOutput this function receives the staff ID and his/her total salary as
parameters, and writes them into the output file.
findSalary this function receives the staff ID from the user, finds the data of that
particular staff ID from the input file, and returns the staff ID and his/her salary
printSlip this function receives the staff ID and total salary of the particular staff returned
by the findSalary function, and displays it in the following format:
(the staff ID is 1111 and the total salary is RM 2150.00)
Salary for month: February 2010
ID No : 1111
Net Income: RM 2150.00
Making a C program, to record the subjects taken by a student, the subjects removed, the approved and disapproved and calculate the GPA for that semester.
The program should have the option of "going out"
Superb collection..thanks !!
just one bug to notify in Q.14..printf("Size of structure is: %d",*ptr); *ptr should be changed to ptr
Question 14 is correct one. No bug. It will work only Turbo c3.0
woov very good post.. thanks a lot to author...
superr collectionnnnnnn.............
great job what a super collectionnnnnnnnnnnn
i want a c program that will display this output:
A B C D E F G F E D C B A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
Wonderful site.The effort of the site-creator is commendable.Keep it up.Your info. was quite useful.
great post!!
#include
void main()
{
int no_of_lines, alphabet = 65, i, count, j;
printf("\nenter the number of lines you want to print\t:");
scanf("%d",&no_of_lines);
count=2*no_of_lines;
for(j=0;j<no_of_lines;j++)
{
if(j==0)
{
printf("\n\n");
for(i=0;i<count;i++)
{
if(i<no_of_lines)
{
printf(" %c", alphabet++);
}
else if(i == no_of_lines)
{
alphabet--;
}
else
{
printf(" %c",--alphabet);
}
}
}
else
{
printf("\n");
//printf("\nnothing\n");
for(i=0;i<count-2*j;i++)
{
if(i<no_of_lines-j)
{
printf(" %c", alphabet++);
}
else
{
printf(" %c",--alphabet);
}
}
}
}
}
SAMPLE OUTPUT:
enter the number of lines you want to print : 5
A B C D E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
if u want dat particular format enter the number of lines as 7....
Great work ..Lots of hard work ...thanks a lot..becz it helps me a lot
main()
{
float a=0.7;
if(a<0.7)
printf("c");
else
printf("c++");
}
output:c
Can anybody explain this plz
Hi Anil,
Check the question(4) of following link
http://cquestionbank.blogspot.com/2010/04/c-questions-answers.html
I think It will help you.
Good work.
Also check this blog:
http://cquestion.blogspot.com/
main()
{
float a=0.7;
if(a<0.7)
printf("c");
else
printf("c++");
}
Exp:
in the above program the compiler take it('a') as 0.7000001,so a<0.7 i.e true.so ,it's o/p is "c".
its not enough to learn "c" need some more, this is very nice collection,thank full to you
void main()
{
int i;
char j;
for(i=71;i>=65;i--)
{
for(j=65;j<=i;j++)
{
printf("%c",j);
}
printf("\n");
}
output:-
ABCDEFG
ABCDEF
ABCDE
ABCD
ABC
AB
A
void main()
{
int i;
char j,k;
for(i=71;i>=65;i--)
{
for(j=65;j<=i;j++)
{
printf("%c",j);
}
for(k=i;k>=65;k--)
{
printf("%c",k);
}
printf("\n");
}
output:-
ABCDEFGFEDCBA
ABCDEFFEDCBA
ABCDEEDCBA
ABCDDCBA
ABCCBA
ABBA
AAA
C is a very interesting language and this is a basic of all language, if we have no knowledge of c then we cant understand c++, this is a 1st stage of all programing language.
Great! this post is very help for me.
Great work...really worthable one
awesum collection...
Awesome awesome awesome awesome awesome.......
really...helpful
awesome awesome awesome awesome awesome awesome awesome awesome awesome awesome awesome xcllnt work..............:))))))
thnks that was a nice info
http://www.train4job.com/
great post
good but need little more
all questions are very easy questions pls post difficult question and their answers
good
Thanks u vary much to create such super blog
thank you sooooooooooooooooooooooo much...i find these questions so very useful...i could now confidently face my placement interviews..thanks once again..
I need answer for this question immediately before 3 hrs .. pls help me
1.write a c program to divide the no. 73897869by 256 without using +,-,/,* and loop statement??
and this too!
write 2 main () independent functions without using comments in a single program..pls help me friends i need the answer the answer immediately
Wow....thats great. I have my Class Notes on C Programming. I shared them in my blog
Tanmay On Run
But your posts are much more helpful, My post will be helpful for class notes. But these posts are helpful for practicing. Nice to find your blog.
This is awesome post and good imformation
C interview questions
1)void main()
{
float a=2.1;
if(a==2.1)
printf("TE");
else
printf("BE");
getch();
}
------------------------------------------------------
Whats the OUTPUT of Following Program
2)void main()
{
float a=2.0;
if(a==2.0)
printf("TE");
else
printf("BE");
getch();
}
give Ans with reason....:)
Hi Anurag,
Please check the question (1) of the following link: http://cquestionbank.blogspot.com/2009/09/c-operator-question-with-detial.html
I hope it will help you.
thanks a lot sir..........
super..................site,&&&&&&&&&&&&&&&
super collection.
very very helpful, thank you!
excellent work
thanks............
supper.....D:)
i didnt even expect this much of material ..thanq :) i think it definitly helps me alot..:)
In the program for dangling pointer if ptr=call()
is written before clrscr() then it prints garbage value ...if written after it prints 26 correctly......Plz explain this..........using turbo C
good very good
Write a program for a GENERAL NUMBER CONVERTERS which include
binary, decimal, octa and hexadecimal. You need to write the program using C
language.
Hi,
I hope this link will help you
http://cquestionbank.blogspot.com/2010/07/c-program-examples.html
Check Conversion ( Number System ) section
well frnd i have a question---
why the constructor in c++ can't be virtual but destructor can be?
I really appreciate this. I shall donate some to this site.
This is very use full for students....
really good collection.....very useful
Anyone plz peast link to find turbo C for windows-7.
i have turboC.exe setup but not working properlly.
Count the total words in a sentence,count once if word repeatting without using lib function.
eg- my name is jawed,my pet name is dog.
Answer-6
all genius....
great work...
void main()
{
float a=2.1;
if(a==2.1)
printf("TE");
else
printf("BE");
getch();
}
In the above program a is float value but 2.1 value directly substituted in program taht value take double datatype.
-- float takes after dot(.) 8 zero's.
-- Double takes after dot(.) 16 zero's.
so.....float is not equal to double.
ans is BE.
write a program to find the rank of the number in the one dimensional array without using sorting and using two arrays
c++ has any site like c
nice job i didn't see this type of stuff .Why don't you make website, we will made website with low price consult us sankar00002009@gmail.com
yes. good
thanks
// This program is written in JAVA language .Which language u r using u can change
public class BB5
{
public static void main(String aa[])
{
int n=20;
int a=1;
int b=n/2;
int c=65+b;
for(int k=1;k<=(n/2+1);k++)
{
for(int i=65;i<=c;i++)
{
System.out.printf("%c",i);
}
for(int j=65+b;j>=65;j--)
{
System.out.printf("%c",j);
}
c--;
b--;
System.out.println();
}
}
}
#include
#include
void main()
{
int i,j;
clrscr();
for(i=9;i>=1;i++)
{
for(j=i-1;j<=i;j--)
{
printf("%d",j);
}
printf("\n");
}
getch();
}
I Think of your talents as the things you’re really good at. They’re like personality traits. For instance, you may be a very creative person, or a person who’s really good at attending to details or a person with a gift for communicating. Your talents are the base for any successful business venture, including a home-based business.
Excellent work . . .thank u
wonderful info abt C
information is very good
great job, really wonderful info.
yup the (0.7) in the if statement is by default double type
and float is always less as to double!!
so,float a=0.7 is always less than (0.7 which has it's default datatype double)!!
:-)
very well written and organized tutorials…its indeed a great help for beginners like me to keep up the interest and at the same time learn this important subject.
Cbse Entrancei
Post a Comment