Академический Документы
Профессиональный Документы
Культура Документы
com
2008
C Intervew Ouestons
And Answers
V s t T e c h P r e p a r a t o n . c o m f o r mo r e n t e r v e w q u e s t o n s a n d
a n s w e r s
C lnterview uestions and Answers
What is C language?
The C programmng anguage s a standardzed programmng anguage
deveoped n the eary 1970s by Ken Thompson and Denns Rtche for
use on the UNIX operatng system. It has snce spread to many other
operatng systems, and s one of the most wdey used programmng
anguages. C s przed for ts effcency, and s the most popuar
programmng anguage for wrtng system software, though t s aso
used for wrtng appcatons.
printf() Function
What is the output of printf("%d")?
1. When we wrte prntf("%d",x); ths means comper w prnt the
vaue of x. But as here, there s nothng after %d so comper w show
n output wndow garbage vaue.
2. When we use %d the comper nternay uses t to access the
argument n the stack (argument stack). Ideay comper determnes
the offset of the data varabe dependng on the format specfcaton
strng. Now when we wrte prntf("%d",a) then comper frst accesses
the top most eement n the argument stack of the prntf whch s %d
and dependng on the format strng t cacuated to offset to the actua
data varabe n the memory whch s to be prnted. Now when ony %d
w be present n the prntf then comper w cacuate the correct
offset (whch w be the offset to access the nteger varabe) but as
the actua data ob|ect s to be prnted s not present at that memory
ocaton so t w prnt what ever w be the contents of that memory
ocaton.
3. Some compers check the format strng and w generate an error
wthout the proper number and type of arguments for thngs ke
prntf(...) and scanf(...).
Vst http://TechPreparaton.com for more Intervew Ouestons wth Answers Page 2
malloc() Function- What is the difference between "calloc(...)" and
"malloc(...)"?
1. caoc(...) aocates a bock of memory for an array of eements of a
certan sze. By defaut the bock s ntazed to 0. The tota number of
memory aocated w be (number_of_eements * sze).
maoc(...) takes n ony a snge argument whch s the memory
requred n bytes. maoc(...) aocated bytes of memory and not bocks
of memory ke caoc(...).
2. maoc(...) aocates memory bocks and returns a vod ponter to the
aocated space, or NULL f there s nsuffcent memory avaabe.
caoc(...) aocates an array n memory wth eements ntazed to 0
and returns a ponter to the aocated space. caoc(...) cas maoc(...)
n order to use the C++ _set_new_mode functon to set the new
hander mode.
printf() Function- What is the difference between "printf(...)" and
"sprintf(...)"?
srinif(...} wriics daia io iIc cIaracicr array wIcrcas rinif(...} wriics daia io iIc
siandard ouiui dcvicc.
Compilation How to reduce a final size of executable?
Sze of the fna executabe can be reduced usng dynamc nkng for
brares.
Linked Lists -- Can you tell me how to check whether a linked list is circular?
Create two ponters, and set both to the start of the st. Update each
as foows:
whe (ponter1) {
ponter1 = ponter1->next;
ponter2 = ponter2->next;
f (ponter2) ponter2=ponter2->next;
f (ponter1 == ponter2) {
prnt ("crcuar");
}
}
Vst http://TechPreparaton.com for more Intervew Ouestons wth Answers Page 3
If a st s crcuar, at some pont ponter2 w wrap around and be
ether at the tem |ust before ponter1, or the tem before that. Ether
way, ts ether 1 or 2 |umps unt they meet.
"union" Data Type What is the output of the following program? Why?
#ncude
man() {
typedef unon {
nt a;
char b|10|;
foat c;
}
Unon;
Unon x,y = {100};
x.a = 50;
strcpy(x.b,"heo");
x.c = 21.50;
prntf("Unon x : %d %s %f n",x.a,x.b,x.c);
prntf("Unon y : %d %s %f n",y.a,y.b,y.c);
}
What does static variable mean?