1000 c programming questions
TRANSCRIPT
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
1/123
1. typedef struct{char *;nodeptr next;} * nodeptr;what does nodeptr standfor?ans:
2. int *x[](); eans
ans:expl: Elments of anarray can't be functions.
!. struct "ist{int x;struct "ist *next;}*head;the struct head.x #1$$%ns: a&o'e is correct wron
exp": Before using theptr type struct variablewe have to give memoryto that .And also whenever the struct variableis ptr then we accessthemembers by "-"operator.
.ain()
{int i;i#1;
i#i+2*i++;printf(,d-i);}ans: !
. ain(){
/0 *fp1-*fp2; fp1#fopen(3one3-3w3) fp2#fopen(3one3-3w3) fputc(4%4-fp1) fputc(454-fp2) fc"ose(fp1) fc"ose(fp2)} a.error &. c. d. ans: no error. But t willover writes on same file.
6. 7inc"ude8a""oc.h9 char *f() {char *s#a""oc(); strcpy(s-3ood&ye3);} ain() { char *f();
printf(3,c3-*f()#4%4);} op#?
for strcpy functionstring.h header file should beincluded semicolon is missing in
strcpy functionleftside function call cancome when it isreturning some pointerso #p$%A%&
. 7define #-#$;# );printf(3,d ,d ,d 3-i->-);
}
ans. ( )
. ain() { int a#1$-- c#!-d#!; if (a8&)@@(c#d++) printf(A,d ,d ,d ,dB-a-&-c-d); e"se
printf(3,d ,d ,d ,dB-a-&-c-d); }
ans: * + , , ote: if conditionshould be in braces
C. ain() { int i # 1$; printf(3 ,d ,d ,d Dn3- ++i-i++- ++i); }
ans: , 1$. ain() { int *p- *c- i;
i # ; p # (int*)(a""oc(siEeof(i))); printf(3Dn,d3-*p); *p # 1$; printf(3Dn,d ,d3-i-*p); c # (int*) ca""oc(2); printf(3Dn,dDn3-*c); }
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
2/123
ote: calloc functionhas less parameters callocn/elemsi0e1
ain()
{
int *p- *c- i;i # ;p # (int*)
(a""oc(siEeof(i)));printf(3Dn,d3-*p);*p # 1$;printf(3Dn,d ,d3-i-*p);c # (int*) ca""oc(2-2);printf(3Dn,dDn3-*c);}
ans: garbage/ +/ */ * malloc givesgarbage and calloc initiali0es with0eros1
11. 7define #-#$; # ); printf(3,d..,d..,d3-i->-); }
ans: ( )
12. ain() { enu Fta{ "eft#1$- riht-front#1$$- &ac}; printf(3"eft is ,d- riht is
,d- front is ,d- &ac is,d3-"eft-riht-front-&ac); }
ans: left is */ right is/ front is **/ bac2 is *
1!. ain(){int a#1$-$;a9#?$$:$$;printf(3,dDn3-&);}
ans: lvalue re3uired for
ternary operator
1. 7define GH0IJ(int) printf(3int # ,d3-int)
ain() { int x-y-E; x#$!;y#$2;E#$1; GH0IJ(xKx); E88#!;GH0IJ(x);
y99#!;GH0IJ(y); }
ans: int $ * int $ , int $*
1. ain()
{ char s[] # 35ouLuets and5ric&ats3; printf(3Dn,c- 3-*(@s[2])); printf(3Dn,s- 3-s+);
printf(3Dn,s-3-s); printf(3Dn,c3-*(s+2)); }
ans: u/ets and Bric2bats/Bou3uets and
Bric2bats/ u
16. ain()
{struct s1{char *str;struct s1 *ptr;};static struct s1 arr[] #{ {3Mydera&ad3-arr+1}-
{35ana"ore3-arr+2}-{3Ne"hi3-arr}};struct s1 *p[!];int i;
for(i#$;i8#2;i++)p[i] # arr[i].ptr;
printf(3,sDn3-(*p)O9str);printf(3,sDn3-(++*p)O9str);printf(3,sDn3-((*p)++)O9str);
}
ans: Bangalore 4elhi 4elhi
1. ain(){char *p # 3he""o wor"dP3;p[$] # 4M4;printf(3,s3-p);}
ans: 5ello world
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
3/123
1. ain(){int x#1-y#1;whi"e( (x 9 $) @@ (y 9 $) ){ printf(3,16d,16d3-x-y); x +# y;
y +# x; }}
ans: here x $ x6y and y$ x6(y when y goesbeyond ,(7)7 it falls in8ve side and loop brea2s
1C. int f(int p)
{
int i # $- t # 1- s # 1;
whi"e( s 8#
p)
{
i++;
t +# 2;
s +# s;
}
return i;
}
ans: this function gives
the no. of bits re3uired
to represent a number
in binary form
2$. remove the duplicate from
a sortedarray.
21. fibonacci series upto 100
recursively.
22. ain()
{
char c[]={ "
enter" , "first" , "print" ,
"new" }.
char !!cp[]={c#,c$, c1, c}
char !!!cpp[]=cp
printf%"&s", !cp'
printf%"&s",((!cp'
}
ans: lvalue re3uired forsecond printf statement
2!. QRN and R< proras
2. Srite a prora to print12 2! ! ! .
ans:main1
9int i/&
fori$&i;$+&i661 9 printf"
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
4/123
2. Srite prora to print12 ! 6 C 1$
11 12 1! 1
ans:
main19int i//2&
2 $ & fori$&i;$+&i661
9for$i&*&--1printf"=d"/2661&
printf"
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
5/123
Mow can 0 read a directory in a Rprora?
Mow can 0 increase the a""owa&"enu&er of siu"taneous"y open fi"es?
Shat4s wron with the ca""3fopen(3c:DnewdirDfi"e.dat3- 3r3)3?
!$. ain(){int x#1$-y#1;x#x++;y#++y;printf(3,d ,dDn3-x-y);}
ans: )
!1. int x;
ain(){
int x#$;{int x#1$;x++;chaneF'a"ue(x);x++;
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
6/123
tep#a;a;a#tep;return;}
ans:
* +* +
!6. ain(){ char *ptr # 3HacoUystes3;(*ptr)++;printf(3,sDn3-ptr);ptr++;printf(3,sDn3-ptr);}
ans:
Famco Fystemsamco Fystems
!. ain(){ char s1[]#3Haco3;char s2[]#3Uystes3;s1#s2;printf(3,s3-s1);}
ans: lvalue re3uired sis base address ofarray1
!. ain(){char *p1;char *p2;p1#(char *) a""oc(2);p2#(char *) a""oc(2);strcpy(p1-3Haco3);strcpy(p2-3Uystes3);strcat(p1-p2);printf(3,s3-p1);}
ans: DamcoFystems
ote: ;malloc.hshould be included1
!C. % code "ie this is i'en.a. for(i#$;i8nu;i++)&. for(i#nu;i9$;iOO)%ssuin no code optiiEation andassue that the icroprocessorhas f"as etc. which one is faster.
Ans: b will execute faster.
$. ain(){int a#1--c#!;printf(3,d-,d3-a-&-c);}
ans: / (
1. ain(){struct{char a[!];int &;}x;char *cp;printf(A,d,dB-siEeof(cp)-siEeof(x));}
ans: ! + since pointercp stores address,(-bit1 ! bytes it ta2es andand x ta2es + bytes,for character array aand ( for int b1
2. ain(){int p#!-L#;L # shw(@p);printf(3,d ,d3-p-L);}
int shw(int *a){*a # 1$;}
ans: * garbage
!. write *a inters of +-O-88
ans: x;;,-x1
. ain(){
char *s1 # 3he""o3-*s2#3a&ce3;strcpy(s1-33);s2[$] # s1[$];printf(3,d,d3-str"en(s1)-str"en(s2));}
ans: * *
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
7/123
. ain(){int i#1$;printf(3,d,d,d3-i-i++-++i);}
ans: ( compilerdependent1
6. const char *char * constShat is the differnce &etween thea&o'e two?
ans: const char # pointerto a constant character char # const constant
pointer pointing to a character
. ain(){char *x#3new3;char *y#3dictonary3;char #t&'oid swap (char * - char *);swap (x-y);printf(3(,s- ,s)3-x-y);
char #t&t#x;x#y;
y#t;printf(3O(,s- ,s)3-x-y);}'oid swap (char *x-char *y){char *t;y#x;x#y;y#t;}
ans: multipledeclaration of t and alldeclarations should bebefore executable
statementerrors1
. ain(){char p[]#3strin3;char t;int i->;for(i#$->#str"en(p);i8>;i++){
t#p[i];p[i]#p[>Oi];p[>Oi]#t;}printf(3,s3-p);}
ans: will not printanything since p will bepointing to a null string
C. ain(){int i#1$;printf(3,d ,d ,d3-i-++i-i++);}
ans: ( ( * compilerdependent1
$. ain(){'oid f(int-int);int i#1$;f(i-i++);}'oid f(int i-int >){if(i9$)return;i+#>;f(i->);printf(3,d-3-i);}
ans: + ! , ( i$/$* for function If%1
1. ain(){'oid f(int-int);int i#1$;f(i-++i);}'oid f(int i-int >){if(i9$)return;i+#>;
f(i->);printf(3,d-3-i);}
ans: ++ !! ,, (( i$/$ for function If%1
2. ain(){char *s#3he""o wor"d3;
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
8/123
int i#;printf(3,.*s3-i-s);}
ans: hello w
!. ain()
{int a-&;printf(3enter twonu&ers :3);scanf(3,d,d3-a-&);printf(3,d+,d#,d3-a-&-a+&);}
ans: will generate runtime error Jcoredump
. ain(){
union{int x;char y;struct {char x;char y;int xy;}p;}L;printf(3Dn ,d-
,d3-siEeof(L)-siEeof(int));}
ans: !/(
. ain() {char *x#3Utrin3;char y[] # 3add3;char *E;E#(char *) a""oc(siEeof(x)+siEeof(y)#1);strcpy(E-y);strcat(E-x);printf(3,s+,s#,s3-y-x-E);}
ans: Kvalue re3uired
6. an array of n pointers to function
returnin pointers tofunctions returnin pointers tocharacters
ans: char # # *x?n@1 1 11
pointer to array of int- char etc.-this is array pointer
ans: int #x1?@ char#x1?@
array of pointer to int- char etc.-this is pointer array
ans: int #x?@ char
#x?@
function returnin pointer to int-char etc.-
ans: int #x1 char #x1
pointer to function returnin int-char etc.-
ans: int #x11 char #x11
function returnin pointer to arrayof pointer to function returnin
char
ans: char ##x11 ?@1 1
array of pointer to functionreturnin pointer to array of char
ans: char ##x?@1 1 1 ?@
. ain(){enu nu&er { a#O1-
-c-d-e};
printf(3,d3-e);}
ans: 7
. ain(){int i#$;for(i#$;i82$;i++){switch(i){case $:i+#;case 1:i+#2;case :i+#;
defau"t: i+#;&rea;}printf(3,d-3-i);}}
ans: )/( after caseand default colon should bethere1
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
9/123
C. ain(){int i- count- x#1;
for(i#$- count#$;i816;i++)if( P(x@(188i)) )
count++; printf(3,d3-count);
}
ans: + no. of 0eros1
6$. ain(){int i- count- x#1;
for(i#$- count#$;i816;i++) if(x@(188i) ) count++; printf(3,d3-count);
}
ans: no. of ones1
61. which one wi"" o'er f"ow i'en twoproraspro 1: pro2:
ain() main1{ {int fact; int fact$*"on int x; fori$&i;$n&i661fact#factora"(x); fact$fact#i&} }
int factoria"("on int x){if(x91) return(x*factoria"(xO1);
}
ans: program program ( isalways 0ero since fact $*1
62. ain(){char str[]#3he""o3;if(str##IW) printf(3strinnu""3);e"se printf(3strin notnu""3);}
ans: string not null
6!. 'oid f(int 'a"ue){for (i#$;i816;i++){if('a"ue @$x$$$991)printf(313)e"se printf(3$3);}}
ans: binary output ofvalue
6. 'oid f(int *p){static 'a"#1$$;
'a"#@p;}ain(){int a#1$;printf(3,d 3-a);f(@a);printf(3,d 3-a);}
ans: nonportablepointer conversion wecan%t store address ininteger variable/ wehave to ta2e pointer to
store address1
6. ain(){int x- *y;x # y;printf(A,dB-x);}
ans: nonportablepointer conversion
66. 7 define f(a-&) a+&
7define (c-d) c*dfind 'a"ue of f(-(-6))
ans: ,!
6. ain(){char a[1$]#3he""o3;strcpy(a-4D$4);printf(3,s3-a);}
ans: arguments must bea string constant orcharacter array variable
here it is constatcharacter not a stringconstant. 5enceprogram error
6. char a[][1];int &[][1];address of a $x1$$$ and & is$x2$$$ find address of a[!][] and&[!][]
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
10/123
interer taes !2O&its andcharacter taes O&its
ans: a?,@?!@ $ *x*,b?,@?!@ $ *x(*L!
ote: addresses are inhexadecimal1
6C. Qi'en an interer in &inaryfor-find the nu&er of ones inthat nu&er without countin each&it.(Jhis Luestin is notu"tip"e choice Luestion. JhisLuestion carries orears. Uo p"ease tae care for thisLuestion.)
ans: C.Ditchie
$. ain(){
a#2;!;x#UW
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
11/123
{int i # 1;for();for();printf(3Dni # ,dDn3- i+1);}
ans: ! printfs will occurand i $ (
. 7define
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
12/123
printf(3Gass 13);if(p[siEeof(p)O2]##44)printf(3Gass 23);e"seprintf(3/ai" 23);}e"se
{printf(3/ai" 13);if(p[siEeof(p)O2]##44)printf(3Gass 23);e"seprintf(3/ai" 23);}
ans: ail Pass (
. % code which had soedec"arations of soe data ites.Jhere were a coup"e of nora" dataites (char- int..) and soepointers as we"" and a a""oc ca"".
You ha'e to find the tota" eorytaen up in the stac (Mint:Gointers and a"" are a""ocated inheap- not in stac- so donZt countthe).%"so in ost ofthese Luestions- theywere specifyin that the VU was !2&it.
. % structure was i'en and itcontained nora" data as we"" assoe &itOwise data. You had to findthe tota" siEe taen up &y thestructure
C. Gointer to a function whichreturned an array of char pointers
ans: char ##x11 1 ?@
C$. a"ue of 2 particu"ar 'aria&"es inR(
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
13/123
return(n);}
ans: unpredictableoutput. auto variableaddress should not bereturned. t will lose its
scope when it comes outof the bloc2.
C6. char *f()ain()
{char *a-*f();a#f();printf(3,s3-a);}char *f(){return(3Me""o Sor"d3);}
ans: 5ello Sorld
C. what is the errorain()
{int >#1$;switch(>){case 2$:pritnf"Kess than (*"1&&rea;case !$:printf(3ess than !$3);&rea;defau"t:printf(3he""o3);}
ans: printf not pritnfand one brace > is missing
C. which is 'a"id :(i)char arr[1$];arr#3he""o3;(ii) char arr[]#3he""o3;
ans: second is correct. n firstlvalue re3uired.
CC. ain(){char *str;
str#(char*)a""oc(2$*siEeof(char));strcpy(str-3test3);strcat(str-4P4);printf(3,s3-str);}
ans: strcpy functionarguments should beeither a character array
variable or a stringconstant. nstead of I%give TU
1$$. Mow any ties ain is et ca""edain()
{
printf(3\u&oree3);ain();}
ans: till stac2 overflow
1$1. ain(){int i;if(i#$)printf(3 Me"" 3);e"seprintf(3Mea'en3);}
ans: 5eaven
1$2. ain(){int i->;for(i#$->#$;i8->82;i+
+->++);printf(3,d ,d3-i->);}
ans: (+ (+ A pair ofexpressions separatedby a comma is
evaluated left to right/and the type and valueof the result are thetype and value of theright operand. 5erewe%ve to consider ;(+condition.
1$!. 1)pointer to a function.2)pointer to structure.!)static 'aria&"e and difference&w(const char *p-char const*p-const char* const p).)pass &y 'a"ue @ reference.)strin "i&rary functions(syntax).
6)Srite a prora to copare twostrins without usin the strcp()function.)Srite a prora to concatenatetwo strins.)Srite a prora to interchane 2'aria&"es without usin the thirdone.C)Srite proras for UtrinHe'ersa" @ Ga"indroe chec .
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
14/123
1$)Srite a prora to find the/actoria" of a nu&er.11)Srite a prora to eneratethe /i&inocci Ueries.12)searchin and sortina"ooriths with cop"exities.
1$. Jheory Luestion a&out far pointers.
ans: ar pointers are ! bytesin si0e and local pointers are (bytes in si0e. important: i sawin a previous 3uestion paper ofaccenture which is in thechetana database/ some ladywrote that si0e of an integer inL is ( bytes and for L66 it is !bytes. Ghis is absurd.Ghe si0eof types is entirely dependenton the compiler used.for 4OFGurbo L si0eof int is ( and floatis ! bytes for windows borland
L/L66 si0e of int is ! bytes forlinux gcc/ si0e of int is ( bytes.All these depends on theOperating system.Please 2eepthis in mind.
1$. ain(){char str[]#{3he""3};
int i; for(i#$;i8;i++) printf(3,c,c,c,cDn3-str[i]-i[str]-*(str+i)-*(i+str));
}
ans: hhhheeeellllllll
1$6. in"ine function does type checinand so it is &etter than a acro
1$. ain(){int i # 1$;int > # i 99 1$;printf(3,d3->);}
ans: *
1$. char *str # 3Me""o3;char arr[] # 3Me""o3;arr++; HHVH..its "ie a pointerconstant*(arr + 1) # 4s4;cout88arr; op: Ms""o
1$C. struct Nate{ int yr; int day; int onth;} date1-date2;
date1.yr # 2$$;date1.day # ;date1.onth # 12;now how wi"" youinitia"iEe date2(without e&er&y e&erassinent)ans: date( $
date&
11$. ain(){extern int a;printf(3,d3-a);;
}int a#2$;
ans: (*
111. ain(){int a[]#{2-!};printf(3Dn ,d ,d
,d3-a[2]-a[!]-a[]);}
ans: * * * if there arefewer initiali0ers uninitiali0ed
variables are 0ero
112. ain(){inti#O!->#2-#$-;#++i@@++>++;printf(3Dn ,d ,d ,d,d3-i->--);}
ans: -( , *
11!. ain(){int a-&;
a#sudi(12!);sudi(12!);printf(3,d ,d3-a-&);}sudi(int n){static int s#$;int d;if(nP#$){
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
15/123
d#n,1$;n#(nOd)1$;s#s+d;sudi(n);}e"se return(s);}
ans: ) (
11. 7define RW5(x) (x*x*x)ain()
{int a-!;a#RW5(&++);printf(3Dn ,d ,d3-a-&);}
ans: (7 )
11. ain(){
const int x#et();printf(3,d3-x);}et(){return(2$);}
ans: (* for autovariables initiali0ers canbe function calls orsome expressions. Butfor static initiali0ersshould constants or
constant expressions.
116. % function has this prototype 'oidf1(int **x)- Mow wi"" you ca"" this function?
{a) int **a; (&) int a; (c) int*a; (d) int a#;
f1(a); f1(@a); f1(@a); f1(@@a);
ans: int #a& fa1&
11. ain(){int "#1;for(;;){
printf(3,d3-"++);if("91$)&rea;}}
ans: (,!+)7MH*
11. ain(){
char str[]#3fast3;static char *ptrFtoFarray #
str;printf(3,s3-ptrFtoFarray);}
ans: error. for auto
variables initiali0ers canbe function calls orsome expressions. Butfor static initiali0ersshould constants orconstant expressions.
11C. ain(){char str[]#3fast3;char *ptrFtoFarray # str;printf(3,s3-ptrFtoFarray);}
ans: fast. for auto
variables initiali0ers canbe function calls orsome expressions. Butfor static initiali0ersshould constants orconstant expressions.
12$. ain(){int i#1$;fn(i);printf(3,d3-i);
}fn(int i){return ++i;}
ans: *
121. ain(){int i->;i#1$;>#siEeof(++i);printf(3,d3-i);}
ans: *
122. ain(){struct ep{char nae[2$];int ae;f"oat sa";
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
16/123
};struct ep e # {3tier3};printf(3Dn ,d
,f3-e.ae-e.sa");}
ans: * *.****** f there
are fewer initiali0ers inthe list than members ofthe structure thetrailing members areinitiali0ed with 0ero.Ghere may not be moreinitiali0ers thanmembers.
12!. ain(){char i#$;for(;i9#$;i++) ;printf(3,dDn3-i);}
ans: -(M
12. typedef enurade{QVVN-5%N-SVHUJ-}5%N;
ain(){5%N 1;1#1;printf(3,d3-1);}
ans: errormultipledeclaration for BA41
12. 7define UJY1 charain()
{typedef char UJY2;UJY1 x;UJY2 y;x#2;y#2;printf(3,d ,dDn3-x-y);}
ans: - -
126. 7ifdef JHW
int 0#$;7endif
ain(){int >#$;printf(3,d ,dDn3-i->);}
ans: error since i is notdeclared
12. ain(${char *pNestn-*pUource#30
o'e You Naddy3;
pNestn#(char*)a""oc(str"en(pUource));
strcpy(pNestn-pUource);printf(3,s3-pNestn);free(pNestn);}
ans: Kove Rou 4addy
12. ain(){char a[][]-f"a;a[$][$]#4%4;
f"a#((a##*a)@@(*a##a[$]));
printf(3,dDn3-f"a);}
ans:
12C. ain(){int i#->#-;#++i+++>;printf(3,d3-);}
ans: lvalue re3uired 66i661
1!$. ain(){int $;int *p#@&;*p++;printf(3,d3-*p);}
ans: un2nown valuevalue at memorylocation next to thememory location of b
1!1. ain()
{int i#$->#$whi"e (i8>){if(8soe condtn9){8&ody of the "oop9i++}e"seif(8soe condtn9)
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
17/123
{ 8&ody of the "oop9>OO}e"se(8soe condtn9){8&ody of the "oop9>OO}
}Mow any ties the &ody
of the "oopis oin to &e executed?
Ans: +* times
1!2. Mow can you inc"ude a "i&rary codewritten in R++ in a source codewritten in R?(Vptions are there)
ans. Fome cross-lin2edplatformcompiler1 is re3uiredfor this.
1!!. ain(){int a[2$]-i;for(i#$;i82$;i++){a[i]#i;}for(i#$;i82$;i++){a[i]#a[2$Oi];}for(i#$;i82$;i++)printf(3,d3-a[i]);}
ans: un2nownvalue H M 7) + ! , ( * ( ,! + ) 7 MH
1!. ain(){int a[2$]-i;for(i#$;i82$;i++){a[i]#i;}
for(i#$;i82$;i++){a[i]#a[2$Oi];}for(i#$;i82$;i++)printf(3,d3-a[i]);}
ans: H M 7 )+ ! , (
* * ( ,! + ) 7 MH
1!. 'oid a&c(int a[]){int #$;int >#$;
whi"e(8>){if(a[i]9a[>])++;e"se>OO;}Mow any ties the "oop
wi"" occur?
Ans: +* times
1!6. ain(){int a[]#{--!-2-1};
int x-y;int *p#@a[2];*p++;x#++*p;y#*(p++);printf(3,d ,d3-x-y);}
ans: , ,
1!. int a; scanf(3,f3-@a); is there any erroror warnin ?
ans. no compile time error butrun time error
1!. ain(){int *p-*L;p#(int *)1$$$;L#(int *)2$$$;printf(3,d3-(LOp));}
ans: +**
1!C. Shen a 4R4 function ca"" is ade-the order in which paraeters
passed to the function are pushedinto the stac is
ans: right to left
1$. ain(){extern int a;a#1$;printf(3,d3-a);
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
18/123
}int a#2$;
ans: *
11. siEeof () operator is used for
ans: data type veriable
12. ain()ain(){int i # 2;printf(3,d ,d ,d ,d 3-i- i+
+-iOO-i++);}
ans: , ( , (
1!. ain(){int i # 2;
printf(3,o"d ,o"d ,o"d,o"d 3-i- i++-iOO-i++);
}
ans: ,ld (ld ,ld (ld
1. Ucope of a "o&a" 'aria&"e which isdec"ared as static?
ans: ile
1. ain(){printf(3 Me""o Do is the wor"d
3); }
ans: 5ello o is the world
16. Shat isint *p(char (*s)[])
ans: p is a functionwhich is returning apointer to integerwhich ta2es argumentsas pointer to array ofcharacters.
1. Mow wi"" u print J%J% a"one froJ%J% GVSH usin strin copy andconcate coands in R?
ans: implement strstrfunction
1. ain(){int n # 1;
switch(n)case 1:printf(3R%U P3);case(2):printf(3defau"t3);&rea;}
ans: error case outside
of switch and misplacedbrea21all 2eywords in c shouldstart with small letters
1C. 7define in((a)-(&)) ((a)8(&))?(a):(&)
ain(){int i#$-a[2$]-*ptr;ptr#a;whi"e(in(ptr+
+-@a[C])8@a[])i#i+1;printf(3i#,dDn3-i);
}
ans: i$+
1$. X(X$88)?ans: Kast M digits are 's
rest are *'s.
11. struct x{int 0;char s;};union
{struct x y;dou&"e >;}E;ain()
{printf(3,d3-siEeof (E));}
ans: M
12. ain(){char
a[]#{414-424-4!4-$-414-424-4!4};
printf(3,s3-a);}
ans: (,
1!. ain(){int
a[]#{414-424-4!4-$-414-424-4!4};printf(3,s3-a);
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
19/123
}
ans:
1. ain(){7define x 1$
{printf(3,d3-x);}}
ans: *
1. ain(){7define x 1${printf(3,d3-++x);}}
ans: lvalue re3uired
16. ain(){char a[]#3%5RN/QM3;printf(3,d3-siEeof(a));}
ans: H
1. ain(){int i#(int*)$x1$$$;printf(3,d3-i);
}
ans: nonportablepointer conversion
1. ain(int 0){printf(3,d3-0);}
ans: command linearguments1
1C. ain(){
printf(3,d3-printf(3he""owor"d3));
}
ans: helloworld *
16$. ain(){int a[2][2][6]{{2-!---6-}
{^^^^^.}}printf(A,u,u,u,uB-a-*a-**a-***a);
assue &ase address is6C
ans: +)7MH+/ +)7MH+/+)7MH+/( a/ a?*@/ a?*@?*@/ a?*@?*@?*@1
161. ain(){int a[2][2]#{{2}-{!}};printf(3,d 3-a[$][$]);printf(3,d 3-a[$][1]);printf(3,d 3-a[1][$]);printf(3,d 3-a[1][1]);}
ans: ( * , *
162. char str&uf[]#3he""o 3;char *strptr#3wor"d 3;str&uf#3wor"d 3;strptr#3he""o3;
ans: error use strcpyfunction1
16!. char str1[]#3he""o3;char str2[]#3he""o3;the conditiona" strin test(str1##str2)returns /%U
ans: use strcmpfunction
16. ain(){int i;char *str#312!four3;i#atoi(str);printf(3,d3-i);}
ans: (,
16. ain()
{char "oop;
for("oop#4%4;"oop8#4E4;"oop++)printf(3,c3-"oop);}
ans: print characters ofascii value from )+ to (
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
20/123
166. ain(){char
s[]#{414-424-4!4-$-414-424-4!4};printf(3,s3-s);}
ans: (,
16. ain() { char *p#BRaritorB; *++p; printf(A,sB-p); *++p; printf(A,sB-*p); }
ans: aritor ritor
16. Mow to print A,B sy&o" in printf?
ans: printfT#2-#$-;# ++>@@++i@@++;printf(3,d ,d ,d
,d3-i->--);}
ans: -( ,
16. ain(){const int i#;printf(3,d3-++i);}
ans: cannot modify aconstant obect
1. 7define 0 6ain()
{printf(3,d3-++0);}
ans: lvalue re3uired
1. ain(){int a[2][!]
[]#{{1-2-!---6---C-1-1-2}-{2-!---6---C-$-$-$-$}};
printf(3,d ,d ,d,d3-a-*a-**a-***a);
}
ans: **( **( **( array begins at address **(1
1C. ain(){printf(3,c3-[3sundara3]);}
ans: m a?i@/ i?a@/ a?(@/(?a@1
1$. ain(){
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
21/123
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
22/123
ans: **** : ***
1C$. ain(){int *>#$x1$$$;printf(3,p3->);}
ans: ****:***
1C1. ain(){int *>#(int *)$x1$$$; (or)
int *>#$x1$$$;printf(3,d3->);}
ans: !*H)
1C2. ain(int x){printf(3,d3-x);
}
ans: command linearguments1
if the nae of theexecuta&"e fi"e is a&c andthe coand "ine isi'en asa&c xyEwhat is the output
ans: (
1C!. ain() {char
a[]#{414-424-4!4-$-414-424-4!4};printf(a);}
ans: (,
1C. 7define const const'oid ain(int arc)
{const int x#$;}
ans: runs fine
1C. ain(){int a[]#{-6};printf(3,d3-a[1.6]);}
ans: )
1C6. struct x{int i#$; *"ine %*};ain(){struct x y; *"ine 5*
}
ans: error i is initiali0edin struct body1
1C. struct {int "en;char *str}*p;++p O9 "en
ans: increments len
1C. ain(){
chara[]#3a&cdefhi>"nopLrstu'wxyE3;
printf(3,d3-siEeof(a));}
ans: (7 si0eof operatorincludes null characteralso/ whereas strlenfunction excludes nullcharacter1
1CC. ain(){
chara[]#3a&cdefhi>"nopLrstu'wxyE3;char *p#a;printf(3,d 3-str"en(p));p+#1$;printf(3,d3-str"en(a));}
ans: () ()
2$$. ain(){printf(3,d3-printf(3 he""o
wor"d 3));}
ans: hello world ,including two spaces1
2$1. what is the output of the fo""owincode- assuin that the array&eins at "ocation !6?
ain(){
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
23/123
int a[2][!][]#{{2-1--!-6----$-C-2-2}-{1-2-!---6---C-$-1-2}};printf(3,u ,u ,u
,u3-a-*a-**a-***a);}
ans:+,)!M7+/+,)!M7+/+,)!M7+/(
2$2. ain(){char a #$x%% ;int & ;& # (int) a ;& # & 99 ;printf(3,x3-&);}
ans: fffa
2$!. Shat is the siEe of the arraydec"ared as dou&"e * =[] ?
ans. + # si0eof double # 1
2$!. 7define c"rscr() 1$$ain()
{c"rscr();printf(3,d3-c"rscr());}
ans: **
2$. ain() {int a;
printf(3,d3-scanf(3,d3-@a));}
ans: it will wait for acharacter from 2eyboard. f uenter any number
it will print .
2$. ain(){
printf(3as3);printf(3D&hi3);printf(3isDn3);}
ans: ahiis
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
24/123
correct address of a[][!]...ache"eent taes &ytes
ans:*7)
212. int a[-6]
how uch eory wi"" &ea""ocated
ans: doubtif commaoperator is considered ( byteswill be allocated1
21!. 7define d 1$+1$ain()
{printf(3,d3-d*d);}
ans: (*
21. ain(){int i->#1;for(i#$;i81$;i++);{>#>+i;}printf(3,d ,d3-i->);}
ans: *
21. static char *i;i#a""oc(siEeof(char));
find the error;
ans: malloc returns voidtype casting is re3uired char#1 1
216. ain(){int i#$xaa;char *p;p#(char *)i;p#p99;printf(3,x3-p);}
ans: illegal use ofpointer p$p!
21. ain(){enu{sunday#O
1-onday-wednesday};printf(3,d
,d3-siEeof(wednesday)-wednesday);
}
ans: (
21. O9Mow do you write a prorawhich produces its own sourcecode as its output?
O9Mow can 0 find the day of thewee i'en the date?O9Shy doesn4t R ha'e nestedfunctions?O9Shat is the ost efficient way tocount the nu&er of &its which areset in a 'a"ue?O9Mow can 0 con'ert inteers to&inary or hexadecia"?O9Mow can 0 ca"" a function- i'enits nae as a strin?O9Mow do 0 access coandO"inearuents?O9Mow can 0 return u"tip"e 'a"uesfro a function?
O9Mow can 0 in'oe anotherprora fro within a R prora?O9Mow can 0 access eory"ocated at a certain address?O9Mow can 0 a""ocate arrays orstructures &ier than 6T?O9Mow can 0 find out how ucheory is a'ai"a&"e?O9Mow can 0 read a directory in a Rprora?O9Mow can 0 increase the a""owa&"enu&er of siu"taneous"y openfi"es?O9Shat4s wron with the ca""
3fopen(3c:DnewdirDfi"e.dat3- 3r3)3?
21C. 'oid ain(){int d#;printf(3,f3-d);}
ans: undefined
22$. 'oid ain(){int i;for(i#1;i8;i++)switch(i)
{case 1:
printf(3,d3-i);&rea;{case 2:printf(3,d3-i);&rea;case !:printf(3,d3-i);&rea;}}switch(i) case
:printf(3,d3-i);
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
25/123
}
ans: (,!
221. 'oid ain(){int i;
for(i#1;i8;i++)switch(i){case 1:
printf(3,d3-i);&rea;{case 2:printf(3,d3-i);&rea;case !:printf(3,d3-i);&rea;}switch(i) case
:printf(3,d3-i);}}
ans: (,
222. 'oid ain(){char *s#3D12!sDn3;printf(3,d3-siEeof(s));}
ans: ! pointer ta2es !bytes here1
22!. 'oid ain(){unsined i#1; * unsined
char # O1 #9 #2; *
sined >#O1; * unsinedor sined int # O1 #9#6! *if(i8>)printf(3"ess3);e"seif(i9>)printf(3reater3);e"seif(i##>)printf(3eLua"3);}
ans: less
22. Mow do you dec"are an array of I
pointers to functions returninpointers to functions returninpointers to characters?
ans: char###a?@1111&
typedef char *pc; *pointer to char *typedef pc fpc(); *function returnin pointer
to char *typedef fpc *pfpc; *pointer to a&o'e *typedef pfpc fpfpc(); *function returnin... *typedef fpfpc *pfpfpc; *pointer to... *
pfpfpc a[I]; * arrayof... *
$$). int f%'void main%'
{f%1'f%1,$'f%1,$,#'}f%int i,int *,int +'{printf%"&d &d &d
",i,*,+'
}
ans: garbage garbage ( garabage ( ,
226. 'oid ain(){int
count#1$-*tep-su#$;tep#@count;*tep#2$;tep#@su;*tep#count;printf(3,d ,d ,d
3-count-*tep-su);}
ans: (* (* (*
22. ain(){static i#!;printf(3,d3-iOO);return i9$ ? ain():$;}
ans: ,(
22. char *foo()
{char resu"t[1$$];strcpy(resu"t-3anythin is
ood3);return(resu"t);}'oid ain(){char *>;>#foo();
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
26/123
printf(3,s3->);}
ans: anything is goodaddress of autovariable should not bereturned. Fometimes it
will give un2nownresults1
22C. 'oid ain(){char
*s[]#{ 3dhara3-3hew"ettOpacard3-3sieens3-3i&3};
har **p;p#s;printf(3,s 3-++*p);printf(3,s 3-*p++);printf(3,s 3-++*p);}
ans: harma harmaewlett-pac2ard
2!$. ain(){static int i # $;int E;if(i++8){printf(3,d 3-i);}e"seexit($);E#!;
printf(3,d ,d 3-E-ain());}
ans: ( , ! +
2!1. ain(){static int i # $;int E;if(i++9){printf(3,d 3-i);exit($);}E#!;
printf(3,d ,d 3-E-ain());}
ans: 7
2!2. ain(){int E#!;printf(3,d ,d @3-E-ain());}
ans: infinite loop or tillstac2 overflows
2!!. ain(){int i#!->#;
whi"e (iOO->OO){printf(3,d ,d Dn3-i->);}}
ans: ( ! ,* (- -( *+ times loop will
be executed
2!. ain()
{int i#!->#;if(iOO->OO)printf(3,d ,d Dn3-i->);}
ans: ( !
2!. ain(){int i#!;printf(3,d ,d ,d 3-+
+i-iOO-i+#);}
ans: M M M
2!6. ain(){int ties #;int i#!;int >#;int #!;i#>+;whi"e(ties OO){i#ties;>#ties;#ties;
}printf(3,d ,d ,d 3-i->-);}
ans: * * *
2!. ain(){int nu #!26;whi"e (nu++);
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
27/123
printf(A,d A-nu);}
ans:
2!. ain(){
f"oat #!.16;printf(3,f ,f
3-f"oor()-cei"());}
ans: ,.****** !.******
2!C. ain(){int nu&er #2;char nae #4%4;printf(3Jhe addition of the
nae and the nu&er is ,o3-nae+nu&er);
}
ans: Ghe addition of thename and the number is ,(
2$. Jhe fo""owin function i'es soeerror. Shat chanes ha'e to &e ade
'oid ( int a-int &){int t; t#a; a#&; t;}
ans: change everywherea to #a and b to #b
21. int ain(){/0 *fp;fp#fopen(3test.dat3-3w3);fprintf(fp-4he""oDn3);fc"ose(fp);fp#fopen (3test.dat3-3w3);fprintf (fp- 3wor"d3);fc"ose(fp);return $;}
0f text.dat fi"e is a"ready presentafter copi"in and execution howany &ytes does the fi"e occupy ?
ans: + bytes22. ain()
{int i;for(i#$;i82$;i++){switch(i){case $:i+#;
case 1:i+#2;case :i+#;defau"t: i+#;&rea;}printf(3,d-3-i);}}
ans: )/ (/
2!. ain(){char c#O6;int i#O!2;unsigned int u $-)&if(c9i){printf(3pass1-3);if(c8u)printf(3pass23);e"seprintf(3/ai"23);
}e"seprintf(3/ai"1-3);if(i8u)printf(3pass23);e"seprintf(3/ai"23);}
ans: ail/ pass(
2. ain(){char c#O6;
int i#O!2;unsigned int u $)&if(c9i){printf(3pass1-3);if(c8u)printf(3pass23);e"seprintf(3/ai"23);}e"seprintf(3/ai"1-3);if(i8u)printf(3pass23);e"se
printf(3/ai"23);}
ans: ail/ ail( chec2with above program1
2. 'oid ain(){int i;char a[]#3Utrin3;
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
28/123
char *p#3Iew Urin3;char *Jep;Jep#a;a#a""oc(str"en(p) + 1);strcpy(a-p); ine
nu&er:Cp # a""oc(str"en(Jep) +
1);strcpy(p-Jep);printf(3(,s- ,s)3-a-p);free(p);free(a);} *ine nu&er 1*
ans: lvalue re3uired atline no. M1
26. ain(){unsined int x#O1;int y;y # X$;
if(x ## y)printf(3sae3);e"seprintf(3not sae3);}
ans: same
2. char *xxx(){static char xxx?*(!@&return xxx;}
ain(){char *#3strin3;strcpy(xxx()-); # xxx();strcpy(-3o"dstrin3);printf(3Jhe strin is :
,s3-xxx());}
ans: Ghe string isoldstring
2. 'oid ya""oc(char *x- int n){
x# (char*)a""oc(n*siEeof(char));
eset(x-4D$4-n*siEeof(char));}
ain(){char *#3Utrin3;ya""oc(-2$);
strcpy(-3V"dstrin3);printf(3Jhe strin is ,s3-);}
ans: Ghe string isOldstring
2C. ain(){char p[]#3Utrin3;int x#$;ifp$$"Ftring"1{printf(3Gass 13);if(p[siEeof(p)O2]##44)printf(3Gass 23);e"seprintf(3/ai" 23);}e"se{printf(3/ai" 13);if(p[siEeof(p)O2]##44)
printf(3Gass 23);e"seprintf(3/ai" 23);}}
ans: ail Pass (address of array andaddress of string whereit is stored aredifferent1
2$. ain(){
char *p#3Utrin3;int x#$;ifp$$"Ftring"1{printf(3Gass 13);if(p[siEeof(p)O2]##44)printf(3Gass 23);e"seprintf(3/ai" 23);}e"se{printf(3/ai" 13);ifp?si0eofp1-(@$$'g'1printf(3Gass 23);e"se
printf(3/ai" 23);}}
ans: ail ail( addressof array and address ofstring where it is storedare different1
21. ain()
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
29/123
{printf(3,u3-ain);}
ans: *
22. ain()
{printf(3,p3-ain);}
ans: starting address ofmain function x:ysegment : offset1. Eachtime u run startingaddress will change.unction name alwaysgives starting addressof that function.
ain(){printf(3,u3-ain());
}
ans: infinite loop or tillstac2 overflows. mainfunction is calledrecursively infinitetimes or till stac2overflows
2!. ain(){int i#1$;printf(3,d ,d ,d3-i-i++-+
+i);
}
ans: ( compilerdependent1
2. ain(){int *p-*L;p#(int *)1$$$;L#(int *)2$$$;printf(3,d3-(LOp));}
ans: +**
2. find(int x-int y){return ((x8y)?$:(xOy)):}find(a-find(a-&)) is used for?
ans: find out minimumof a/ b
26. find(int x-int y);ain()
{int x-a#-x#find(a-find(a-&));printf(3,d3-x);}
find(int x-int y)
{ return ((x8y)?$:(xOy));}
ans: )
2. ain(){int a;if (a#)printf(3 a is 3);e"seprintf(3a is not 3);}
ans: a is 7
2. ain(){int a#-!-c#;if (a9&)if(&9c)printf(3inner3);e"se printf(3outer3);}
ans: outer else isattached to inner if1
2C. ain(){
int a#2-!-c#;if (a9&)if(&9c)printf(3inner3);e"se printf(3outer3);}
ans: no output else isattached to inner if1
26$. ain(){inc(); inc(); inc();}inc()
{static int x;printf(3,d3- ++x);}
ans: (,
261. ain(){printf(3,d3- str"en(33));
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
30/123
}
ans: * strlen excludesnull character. t is a null string1
262. ain(){
printf(3,d3- siEeof(33));}
ans: si0eof includednull character. t is a null string1
26!. ain(){int a#-printf(3,d3- a+++&);}
ans: 7
26. ain()
{int '#!- *p'#@';printf(3 ,d ,d 3- '-*p');}
ans: , ,
26. ain(){enu
cities{ð"ehe->ericho-naEareth#1->erusa"e};
printf(3,d,d3->ericho-naEareth);
}
ans:
266. difference &etween scanf andsscanf function
ans: sscanfs/...1 ise3uivalent to scanf...1except thatinput charecter areta2en from string s.
26. ain(){
char "ine[$];scanf(3,[KDn]3-"ine);printf(3,s3-"ine);}
ans: if you type this ismanu;enter outputwill be this is manuscanf normally ta2es asingle string but if we
use ?N
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
31/123
ans: error must ta2eaddress of memorylocation1
2. ain(){
printf(3,u3- siEeof(func));}
func(){return $;}
ans: error si0eofoperator operandshould not be functionname1
2. ain(){
printf(3,u3- siEeof(func()));}
func(){return $;}
ans: ( si0eof operatoroperand should not befunction name but it canbe a function call1
26. siEeof operator isruntime
operator
2. %n array whose e"eents are fnpointers whichinturn returns a character
ans: char #x?@1 1&
2. ain(){int n-i#1;switch(n){case 1:printf(313);
case 2:printf(323);defau"t:i#1$;}printf(3i#,d3-i);}
ans: * since n is notinitiali0ed it contains
garbage value hencealmost all the timesdefault case is run1
2C. 7define ax 1$ain()
{
int a-&;int *p-*L;a#1$;C;p$a6b1&3$max&}
ans: error must ta2eaddress of a memorylocation1
2$. ain(){int i;printf(3,d3- @i)+1;
scanf(3,d3- i)O1;}
ans: address of memorylocation i scanffunction reads valueinto a garbage locationif it fall in protectedmemory it gives errorotherwise value will beread into that location1
21. ain(){
int i;f"oat *pf;pf # (f"oat *)@i;*pf # 1$$.$$;printf(3,d3- i);}
ans: runtime error
22. ain(){int i # $xff;printf(3,d3- i882);}
ans: *(*
2!. 7define U_H(x) x * xain()
{printf(3,d3- 22U_H(1));}
ans: ((+
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
32/123
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
33/123
2C2. ain(){printf(3D, 3);printf(3DD, 3);printf(3,, 3);printf(3D,,3);}
ans: = O9pame-3YourIae3);
printf(3,s3- o&>O9pIae);}
ans: runtime errorote: pame should beinitiali0e before using1
2C6. struct /oo{char *pIae;
char *p%ddress;};
ain(){struct /oo *o&> #a""oc(siEeof(struct /oo));o&>O9pIae #
a""oc(1$$);o&>O9p%ddress #a""oc(1$$);strcpy(o&>O9pIae-3YourIae3);strcpy(o&>O9p%ddress-3Your %ddress3);free(o&>);printf(3,s 3- o&>O9pIae);printf(3,s3- o&>O9p%ddress);free(o&>O9pIae);free(o&>O9p%ddress);}
ans: :Rour ame RourAddress
2C. ain(){char *a # 3Me""o 3;char *& # 3Sor"d3;printf(3,s3- stract(a-&));}
ans: stract functionshould be defined orstrcat should be used
2C. ain() {char *a # 3Me""o 3;char *& # 3Sor"d3;printf(3,s3- strcat(a-&));}
ans: 5elloSorld
2CC. ain(){char *a # 33;char *& # 3Sor"d3;printf(3,s3- strcpy(a-&));}
ans: Sorld
!$$. 'oid func1(int (*a)[1$]){printf(3V it wors 3);}
'oid func2(int a[][1$]){
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
34/123
printf(3Si"" this wor?3);}
ain(){int a[1$][1$];func1(a);
func2(a);}
ans: O2 it wor2s Sillthis wor2Xormal argument infunction definitionshould be a pointer toarray or doubledimensional array butnot a pointer to pointerdoble pointer1
!$1. ain(){
printf(3,d- ,d3- siEeof(4c4)-siEeof(1$$));}
ans: (/ (
!$2. ain(){int i # 1$$;printf(3,d3-siEeof(siEeof(i)));}
ans: (
!$!. int f();ain()
{int c # ;printf(3,p ,p ,d ,d3-f-f()-f-f());}
int f(){}
ans: segment:offsetsegment:offset integerinteger all are un2nownvalues. Fegment and
offset values of functionaddress and functionreturn value. Yalues offunction address andfunction return value1
!$. ain(){char c;int i # 6;
c # i;printf(3,d3- c);}
ans: -+)
!$. ain ()
{int x # 1$;printf (3x # ,d- y # ,d3-x-OOx++);}
ans: lvalue re3uired
!$6. ain(){int i #1$- > # 2$;printf(3,d- ,d- 3- >OO - OOi);printf(3,d- ,d3- >++ - ++i);}
ans: (*/ H/ H/ *
!$. ain(){int x#;for(;x##$;xOO){printf(3x#,dDn3- xOO);}}
ans: no output
!$. ain() {int x$+&for(;xP#$;x--){printf(3x#,d 3- x--);}}
ans: infinite loopbecareful here twodecrements/ and x isodd. Fo x$$* neveroccurs1
!$C. ain(){int x$!&for(;x##$;x--){printf(3x#,d 3- x--);}}
ans: x$! x$(
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
35/123
!1$. ain(){int x#;{printf(3x#,d3- xOO);}
}
ans: x$+
!11. ain(){unsined int &it#26;printf(3,d 3- &it);{unsined int &it#12;printf(3,d3- &it);}}
ans: (+) +(
!12. ain(){int i;for(i#$;i8;i++){printf(3,d 3- 1 88 i);}}
ans: ( ! M )
!1!. ain(){
sined int &it#12- i#;for(;i;iOO){printf(3,d 3- &it # (&it 99(i O (i O1))));}}
ans: (+) (M )! ,( )
!1. ain(){sined int &it#12- i#;for(;i;iOO){
printf(3,d 3- &it 99 (i O (iO1)));}}
ans: (+) (+) (+) (+)(+)
!1. ain(){
if (P(1@@$)){printf(3VT 0 a done.3);}e"se{printf(3VT 0 a one.3);
}}
ans: OC am done
!16. ain(){if ((1$) @@ ($1)){printf(3VT 0 a done.3);}e"se{printf(3VT 0 a one.3); }}
ans: OC am done
!1. ain(){sined int &it#12- 5it;{5it # X⁢&it # &it @ X&it ;printf(3,d ,d3- &it- 5it);}}
ans: * -+,
!1. Shat is the difference &etween thefo""owin
a. i#i+1;&. ++i;
ans: 66i is a singleinstruction while ini$i6/ first i6 iscomputed and thenassigned.
!1C. Shat is exception hand"in andhow is it different froerror hand"in...... Shy
is exception hand"in used insteadof error hand"in in soecases and 'ice 'ersa.
!2$. xp"anation of VVG princip"esONata %&straction.ONata ncapsu"ationO0nheritenceOGo"yorphis
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
36/123
ONynaic 5indin.OHeduction of rrors.
!21. ain(){int d-a#-!-c#(a-&);d#(a-&);
printf(3,d ,d3-c-d);}
ans: , , from ,( to,(! thin2 about commaoperator1
!22. ain(){int a#-!-c#a-d;d#(a-&);printf(3,d ,d3-c-d);}
ans: + ,
!2!. ain(){int a#-!-c#(a-&)-d;d#(a-&);printf(3,d ,d3-c-d);}
ans: , ,
!2. ain(){int a#-!-c#(a-&)-d;d#a-&;
printf(3,d ,d3-c-d);}
ans: , + from ,( to,(! thin2 about commaoperator1
!2. Shich one is ha'in pro&"e?int *f1()
{int n;return (n)}
int *f2()
{int *p;*p#!;return p;}
int *f!(){int *p;p#a""oc();
return p;}
int *f(){int n;return (@n)
}
ans: f! is havingproblem as it isreturning address ofauto variable.
!26. *p+#1*p++are these two sae?
ans: not same first oneincrements valuepointed by p and secondone increments
pointer1
!2. int nu[!];nu[!]#2;
ans: array indexexceeds array bounds
!2. ain(){int >#;for(int i#$;i8;i++){>++;
++>;}printf(3,d3->);}
ans: undefined symbol i
!2C. ain(){int >#;for(int i#$;i8;i++){>++;++>;}
printf(3,d3->);}
ans: !
!!$. ain(){char s1[2$]#3he""o wor"d3;s?+@$U
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
37/123
}
ans: nonportablepointer conversion
!!1. ain(){
char s1[2$]#3he""o wor"d3;s?+@$%
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
38/123
}
ans: divide by 0ero error
!1. ain(){int a#1$$$-$$$-c;
("on)c#("on)a*&;printf(3,d3-c);}
ans: error lvaluere3uired1
!2. Ne&uin is the process of findin
ans : logical andruntime errors
!!. usin ternary find out ax of a-&-c
ans: ab1 X ac X a : c1
: bc X b : c1
!. ain(){int a- *& # @a- **c #@&;a#;** c# ;printf(3,d3-a);}
ans: +
!. ain( ){
int i # 1;if(Pi)printf(3Hecursi'e ca""s arerea" painP3);e"se{i # $;printf(3Hecursi'e ca""s arecha""eninDn3);ain();}}
ans: prints Decursivecalls are challenging
infinite times or tillstac2 overflows.
!6. ain(){struct ep{char n[2$];int ae;};struct epe1#{3da'id3-2!};
struct ep e2#e1;if(e1##e2)printf(3structures areeLua"3);}
ans: structures are
e3ual in AF L1 buterror in some othercompilers. 4irectassignment andcomparisons can%t bedone.
!. ain( ){char a[];a[$] # 4%4;printf(3,c3- a[$]);}
ans: si0e of a is
un2nown
!. ain(){printf(3,d ,d,d3-siEeof(4!4)-siEeof(3!3)-siEeof(!));}
ans: ( ( (
!C. ain(){printf(3,c3-3a&cdefh3[]);
}
ans: e
!$. ain(){int a[ ]#{1$-2$-!$-$-$};char *p;p#(char *)a;printf(3,d3-*((int *)p+));}
ans: +*
!1. ain()
{int a[]#{1$-2$-!$-$-$};char *p;p#(char *)a;printf(3,d ,d ,d,d3-*p-*(p+1)-*(p+2)-*(p+!));}
ans: * * (* *
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
39/123
!2. ain(){printf(3,c3-[3sundara3]);}
ans: m
!!. 7define str(x) 7x7define =str(x) str(x)7define oper u"tip"yain()
{char*opernae#=str(oper); *Zmultiply i.e.-TmultiplyUprintf(3,s3-opernae);}
ans: multiply Z/stringi0ing operator
allows a formalargument within amacro definition to beconverted to a string1
!. 7define sLr(x) (x*x)ain()
{int a-!;a#sLr(&+2);printf(3,d3-a);}
ans:
!. ain(){int &;f(2$);printf(3,d3-&);}
f(int a){a(* X return *1:return (*1&}
ans: error in functiondefinition
!6. ain(){int &;f(2$);printf(3,d3-&);}
f(int a){return a(* X *1: (*1&
}
ans: (*
!. Shat error wou"d the fo""owinfunction i'e oncopi"ation.
f(int a-int &){int a;a#2$;return a;}
ans: redeclaration of a
!. ain(){int i#!;i#i++;printf(3,d3-i);}
ans: !
!C. ain(){static char a[]#35o&ay3;char *#o&ay3;printf(3,d,d3-siEeof(a)-siEeof(&));}
ans: 7 ! here pointerta2es ! bytes1
!6$.
ain() {int x # ;printf(3,d ,d3- x++- ++x);return $;}
ans: ) )
!61. ain(){int E # ;printf(3,d3- printf(3 ,d ,d3- E- E));
}
ans: ! ! + three spacesare there total fivecharacters will beprinted by printfstatement1
!62. ain(){
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
40/123
int E # ;printf(3,d3- printf(3 ,d ,d3- E- E));}
ans: !+ !+ 7
!6!. ain( ){int a[ ] # { 1$- 2$- !$- $-$};int >;for (> # $; > 8 ; >++){printf(3,d3- * a);a66&}}
ans: lvalue re3uired
!6. ain()
{0nt n#2$- i # $;whi"e(nOO9$);i # i+n;printf(3,d3-i);}
ans: -
!6. ain(){int i # $; char ch # `%Zdo {printf(A,cB- ch);
} whi"e (i++ 8 ++ch 8#Z/Z);}
ans: AAAAAABL4E
!66. int count- su;ain(){for(count # ; su +#OOcount;);printf(3,d3- su);}
ans: *
!6. ain( ){static f"oat a[ ] # { 1!.2-1.}f"oat *>- *;> # a; # a + 2;> # > * 2;
# 2;printf(A,f,f B- *>- *);}
ans: error pointermultiplication anddivision is illegal1
!6. ain( ){static char s[ ] #AHendeE'ousB;printf(A,dB- *(s+str"en(s)));}
ans: *
!6C. ain(){char **p#3Me""o3;printf(3,c3-*p);
}
ans: 5
!$. ain(){char **p#3Me""o3;printf(3,s3-p);}
ans: 5ello
!1. ain(){
char **p#3Me""o3;printf"=s"/#p1& J# or1printfT=sU/##p1& #J}
ans: error
!2. ain(){char **p#3Me""o3;printf(3,c3-**p);}
ans: error
!!. ain(){char a[]#3Me""o3;printf(3,cDn3-*a66);}
ans: lvalue re3uired
!. ain(){
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
41/123
int a#!--c#1;static int # a8&8cO1;printf(3,d3-);}
ans: illegal initiali0ationfor static initiali0er
should be constantexpression or constant1
!. ain(){int a#!--c#1;int # a8&8cO1;printf(3,d3-);}
ans: *
!6. ain(){char c#O!2;
int i#O6;unsined u#O26;if(c9i)printf(3G%UU1 3);if( i 8 c)printf(3G%UU2 3);e"seprintf(3/%01 3);if(i8u)printf(3G%UU2 3);e"seprintf(3/%02 3);}
ans: PAFF PAFF(PAFF(
!. ain(){int i#;switch(i){case 1:printf(3M""o3);case defau"t: 3case3shou"d not coe with3defau"t3printf(3****3);}
}
ans: error case shouldnot be there withdefault1
!. ain(){static int i#;printf(3,d 3-iOO);
if(i)ain();}
ans: + ! , (
!C. ain()
{int a#-c;int ptr;ptr$a&c##ptr* a;printf(3,d-,d3-c-a);}
ans: error nonportablepointer conversion andinvalid indirection1
!$. ain(){int x#1$-y#-p-L;
p#x9C;L#x9!@@yP#!;printf(3p#,d L#,d3-p-L);}
ans: p$ 3$
!1. ain(){int x#11-y#6-E;E#x##yP#;printf(3E#,d3-E);}
ans: 0$
!2. ain(){int c#$-d#-e#1$-a;a#c91?d91e91?1$$:2$$:!$$;printf(3a#,d3-a);}
ans: a$,**
!!. ain(){int i#O->#O2;
>un(i-@>);printf(3i#,d->#,d3-i->);}>un(i->)int i-*>;{i#i*i;*>#*>**>;}
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
42/123
ans: i$-+/$!
!. 7define IV7define YUain()
{int i#->;
if(i9)>#YU;e"se>#IV;printf(3,d3->);}
ans: error O and REFare not defined1
!. 7define IV $7define YU 1ain()
{int i#->;
if(i9)>#YU;e"se>#IV;printf(3,d3->);}
ans: *
!6. ain(){int a#$xff;if(a889912)printf(3"eftist3);
e"seprintf(3rihtist3);}
ans: rightist
!. ain(){int i#+1;whi"e(Xi)printf(3'icious circ"es3);}
ans: infinite loop
!. Shat4s the use of siEeof( )function... since one cana"ways direct"y write nu&er of&ytes instead ofca""in the function.
ans: for runtimeoperations
!C. ain()
{int p # O2$$;char c;c # p;printf(3,d ,d3- c++- ++c);}
ans: +7 +7
!C$. int a#1;int aint ain()
{int !-a#2;printf(3,i*,i*
,*i3-a-&-a&);}
ans: (#J,#J=#Ji
!C1. Shich one of the fo""owinstateents a""ocates enouh space
to ho"d an array of 1$ inteers thatare initia"iEed to $ ?
ans:int #ptr $ int #1calloc*/si0eofint11&
!C2. ain(){int i->;> # 1$;i # >++ O >++;printf(3,d ,d3- i->);}
ans: * (
!C!. ain(){int >;for(>#$;>8!;>++)foo();}foo() {static int i # 1$;i+#1$;printf(3,d 3-i);}
ans: (* ,* !*
!C. Shat is wron in the fo""owin codeain()
{char *c;c # 3Me""o3;printf(3,sDn3- c);}
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
43/123
ans: 5ello nothingwrong with the code1
!C. ain(){union {int a;
int &;int c;} u-';u.a # 1$;u.& # 2$;printf(3,d ,d Dn3-u.a-u.&);}
ans: (* (*
!C6. ain(){char *str # 312!3;printf(3,c ,c ,cDn3- *str-*(str++)- *(str++));
}
ans: , (
!C. 7define ax(a-&) (a&)?a:&ain()
{int a-&;a#!;printf(3,d3-ax(a-&));}
ans: error undefined
symbol ab when it isreplaced in printfstatement1
!C. ain(){int "en#;char *st#312!63;st # st O"en;printf(3,cDn3-*st);}
ans: some un2character is printed
!CC. func();ain()
{func(1);}func(int i){static char #str$9 "One"/"Gwo"/"Ghree"/"our">&
printf(3,sDn3-str[i++]);return;}
ans: error in declarationand definition. Pointershould be there
$$. ain(){int i;for (i#1;i81$$; i++)printf(3,d ,*xDn3-i-i);}
ans: to HH will beprinted both in decimaland hexadecimal form
$1. struct {int x;int y;
union {int idFno;char *nae;}&;}s-*st;ain()
{st # @s;stOx#1$;stO&.idFno # 1$1;printf(3,d,dDn3-s.x-s.&.idFno);}
ans: error undefinedsymbol i and b. i and bshould not be used asdirect variables. Gheyshould be associatedwith structure variable1
$2. ain(){int >-ans;> # ;ans # count();printf(3,dDn3-ans);}
int count(int i)
{if ( i 8 $) return(i);e"sereturn( count(iO2) +count(iO1));}
ans: -M
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
44/123
$!. ain(){int i#;if(i#$)printf(3stateent 13);e"seprintf(3stateent 23);
}
ans: statement (
$. ain(){char a[2];*a[$]#;*a[1]#;printf(3,d3-@a[1]Oa);}
ans: invalid indirection
$. ain()
{char a[]#3he""ow3;char *he""ow3;char c?+@$"hellow"&printf(3,s ,s ,s 3-a-&-c);printf(3,d ,d,d3-siEeof(a)-siEeof(&)-siEeof(c));}
ans: too manyinitiali0ers c array si0eis less1
$6. ain() {char a[]#3he""ow3;char *he""ow3;char c[]#3he""ow3;printf(3,s ,s ,s 3-a-&-c);printf(3,d ,d,d3-siEeof(a)-siEeof(&)-siEeof(c));}
ans: hellow hellowhellow 7 ! 7 herepointer ta2es ! bytes1
$. int nu[]#{1$-1--22-C$};ain()
{int *p-*L;int i;p#nu;L#nu+2;i#*p++;printf(3,d ,d3-i-pOL);}
ans: * -
$. Vne pointer dec"aration is i'en"ie this:
int *(*p[1$])(char *- char*)xp"ain the 'aria&"e assinent
ans: an array of *pointers to functionswith two characterpointers as argumentsand returning integerpointer.
$C. ain(){char*a[]#{3>aya3-3ahe3-3chandra3-3&uchi3};printf(3,d ,d,d3-siEeof(a)-siEeof(char
*)-siEeof(a)siEeof(char *));}
ans: ) ! ! pointerta2es ! bytes1
1$. Jhe inteers fro 1 to n are storedin an array in a randofashion. &ut one inteer is
issin. Srite a prora to findthe issin inteer.
ans: Ghe sum of nnatural numbers is $
nn61J(. if we subtractthe above sum fromthe sum of all the numbers in thearray / the result isnothing but the missing number.
11. Srite a R prora to find whethera stac is proressin inforward or re'ersedirection.
12. Srite a R prora that re'ersesthe "ined "ist.
1!. 7define
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
45/123
}
ans: maximum is 7careful about bracesnot only in printf butalso in macro definition.
1. ain(){int *p-*L-r;int 'a"ues[!$];p#@'a"ues[$];L#'a"ues+2C;r#++LOp;printf(3,d3-r);}
ans: ,*
1. static int i # ;ain()
{
int su#$;do{su +#(1i);}whi"e($8iOO);}
ans: error divide by0ero1
16. enu ode #{reen-red-orane-&"ue-white};
ain ()
{reen # reen +1;printf(3,d-,d3-reen-red );}
ans: error lvaluere3uired since green isa symbolic constant and$ operator should notbe there in enumdeclaration1
1. int (*(*ptr)(int)) ('oid)
ans: ptr is pointer to
function that ta2es anint value returns apointerto a function with a noargument which returnsa integer
1. char *c[] #{3/03-3N0J3-
3U%HRM3-3RV;char [1$$];
unsined i;};int *ptr1;struct = *ptr2;
ain(){printf(3,d,d3-siEeof(ptr1)-siEeof(ptr2));}
ans: ! !
2$. ain() {int i#;printf( 3 ,d ,d ,d3- ++i-i-i++);}
ans: 7 ) +
21. ain(){int i-> ;for(i#$;i8#1$;i++);for(>#$;>8#1$;>++);printf(3i#,d->#,dDn3-i->);
}
ans: i$/$
22. 7define sLuare(a) (a*a)ain()
{printf(3,d3-sLuare(+));}
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
46/123
ans: (H
2!. ain(){int p # $- L #1;p # L++;p # ++L;
p # LOO;p # OOL;printf(3,d ,d3-p-L);}
ans:
2. ain(){int a - count;int func(int);for (count # 1 ;count8#;++count){a # func(count);
printf(3,d3- a);}}
int func(int x){int y;y#x*x;return(y);}
ans: !H)(+
2. supposin that each inteeroccupies &ytes and each
charactrer 1 &yte - what istheoutput of the fo""owin
prorae?
ain(){int a[] #{ 1-2-!---6-};char c[] # {4a4-4x4-4h4-4o4-44};printf(3,d ,d3- (@a[!]O@a[$])-(@c[!]O @c[$]));}
ans: , ,
26. ain(){struct s1 {int i; };struct s2 {int i; };struct s1 st1;struct s2 st2;st1.i #;st2 # st1;printf(3 ,d 3 - st2.i);}
ans: error differentstruct variables shouldnot assigned using "$"operator.1
2. ain()
{int i->;int at[!][!]#{1-2-!---6---C};for (i#2;i9#$;iOO)for (>#2;>9#$;>OO)printf(3,d3 - *(*(at+>)+i));}
ans: H),M+(7!
2. ain(){int n#1$;
fun(n);}
int fun( int n){int i;for(i#$;i8#n;i++)fun(nOi);printf(3 we"" done3);}howany ties is theprintf stateent executedfor n#1$?
ans: 5efore reachin to
printf stateent it wi"" oesto infinite "oop.
2C. ain(){struct ep{char ep[];int epno;f"oat sa";};struct ep e&er #{ 3J0QH3};printf(3 ,d ,f3-e&er.epno-e&er.sa");
ans: errorarray si0e isnot declared if it isdeclared ans is **.******1
!$. 7 define infinite"oop whi"e(1)ain()
{infinite"oop;
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
47/123
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
48/123
$. ain(int siEeofar -char *ar[]){whi"e(siEeofar)printf(3,s3-ar[OOsiEeofar]);}
ans: f:++)if(a[][>]8) #a[i][>];printf(3,dDn3-);}
ans: error constantexpression re3uired inarray dimension1
!. ain(){int x#1$-y#1;x#x++;y#++y;printf(3,d ,dDn3-x-y);}
ans: )
. ain()
{int x#2$-y#!;x # y++ + x++;y # ++y + ++x;printf(3,d ,dDn3-x-y);}
ans: +7 H!
. ain()
{char *p1#3Iae3;char *p2;p2#(char *)a""oc(2$);whi"e(*p2++#*p1++);printf(3,sDn3-p2);}
ans: un2nown string willbe printed pointer p(points to next characterto null character.
6. ain(){int x#;printf(3,d ,d,dDn3-x-x882-x992);}
ans: + (*
. 7define swap1(a-&) a#a+&;aO&;a#aO&;
ain(){int x#-y#1$;swap1(x-y);printf(3,d ,dDn3-x-y);swap2(x-y);printf(3,d ,dDn3-x-y);}
int swap2(int a-int &){int tep;
tep#a;a;a#tep;return;}
ans: * +* + swap(
won%t swap x and y1
. ain(){char *ptr # 3HacoUystes3;(*ptr)++;
printf(3,sDn3-ptr);ptr++;printf(3,sDn3-ptr);}
ans: Famco Fystemsamco Fystems
C. ain(){
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
49/123
char s1[]#3Haco3;char s2[]#3Uystes3;s1#s2;printf(3,s3-s1);}
ans: error lvalue
re3uired1
$. ain(){char *p1;char *p2;p1#(char *) a""oc(2);p2#(char *) a""oc(2);strcpy(3Haco3-p1);strcpy(p2-3Uystes3);strcat(p1-p2);printf(3,s3-p1);}
ans: DamcoFystems
1. ain(){char a[2];*a[$]#;*a[1]#;printf(3,d3-@a[1]Oa);}
ans: error invalidindirection1
2. ain(){
char a[]#3he""ow3;char *he""ow3;char c[]#3he""ow3;printf(3,s ,s ,s 3-a-&-c);printf(33-siEeof(a)-siEeof(&)-siEeof(c));}
ans: error Goo manyinitiali0ers1
!. ain(){char a[]#3he""ow3;
char *he""ow3;char c[]#3he""ow3;printf(3,s ,s ,s 3-a-&-c);printf(3,d ,d ,d3-siEeof(a)-siEeof(&)-siEeof(c));}
ans: hellow hellowhellow 7 ! 7 pointerta2es ! bytes1
. int a[1$]#{6$--1$---!-2--C};
ain()
{int 'arx-'ary-i;for (i#$;i81$;i++){if('arx8a[i]){'ary#'arx;'arx#a[1];}e"se if ('ary8a[i]){'arx#'ary;'ary#a[i];}printf(3,d ,d
Dn3-'arx-'ary);}}
ans: garbage values ofvarx and vary areprinted * times
. 7define US%G(x-y) t#x;x#y;y#t;ain()
{int x#-y#6;if (x9y)US%G(x-y);
printf(3x#,d y#,dDn3-x-y);}
ans: error undefinedsymbol t1
6. ain(){int i#6;int >;>#su(i);printf(3,d3->);}
su(int x){
int t;if(x8#1) return (1);t#su(xO!)+su(xO1);return (t);}
ans: H
. ain(){
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
50/123
int a[]#{$-2--6-};int *ptr;ptr#a;printf(3,d3- *((char *)ptr+));}
ans: !
. ain(){int 0#!;whi"e(0OO){int 0#1$$;0OO;printf(3,d3- 0);}}
ans: HHHHHH
C. ain()
{char ch;for(ch#4$4;ch8#2;ch++)printf(3,c3- ch);}
ans: infinite loopsigned character variesfrom -(M to (71
6$. x#!function(++x)...'a"ue is passed
to the function
x#!function(x++)...'a"ue ! is passedto the function
61. Shat is runtie "ocata&"e code?
Shat is 'o"ati"e- reister definitionin R
Shat is copi"er and what itsoutput.
62. which of the fo""owin is i""ea" forthe prora?
ain()
{char const *p#4p4;}
1)p++ 2) *p++ !)(*p)++ ) a""
ans: , #p166 cannotmodify a constantobect1
6!.
7define putchar(c) printf(3,c3-c)ain()
{int c#4d4;putchar(c);}
ans: d
6. 'oid ain ('oid){printf(3,d3-printf(3%5RDD3));}
ans: ABL
6. 'oid ain('oid){int a[1$]- i;int *&;( int*) a""oc(1$*
siEeof(int)) ;#b $a?,@&for(i#$;i81$;i++)a[i] #i+1$;printf(3,d3-&[O1]);}
ans: error nonportablepointer conversion1
66. 'oid ain('oid){int a[1$]- i;int *&;
( int*) a""oc(1$*siEeof(int)) ;b $a?,@&for(i#$;i81$;i++)a[i] #i+1$;printf(3,d3-&[O1]);}
ans: (
6. ain(){inta[1$]#{1-2-!---6---C-1$};
int *p#a;int *L#@a[C];printf(3,d3-LOp+1);}
ans: *
6. ain(){int i#6;
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
51/123
int *p#@i;free(p);printf(3,d3-i);}
ans: )
6C. ain(){int i#;i#Pi9!;printf(3,d3-i);}
ans: *
$. ain(){int a[1$];![a]#1$;printf(3,d3-*(a+!));}
ans: *
1. int (*p[1$]) ();
ans: p is array ofpointers that eachpoints toa function that ta2es noarguments and returnsan int.
2. struct ep{
int a$(+&char b?(*@$"tg2"&};
ain(){emp e&e.a#2;strcpy(e.&-3te""apa""i3);printf(3,d ,s3-e.a-e.&);}
ans: error structuremembers should not beinitiali0ed directly andstruct 2eyword should
be there before emp e&1
!. ain(){int a#;const int *p#@a;*p#2$$;printf(3,d3-*p);}
ans: error cannotmodify a constantobect1
. 7define U_(x) x*xain()
{
int a#U_(2+1);printf(3,d3-a);}
ans: +
. ain(){struct t{int i;} a-*p#@a;pO9i#1$;printf(3,d3-(*p).i);}
ans: *
6. a) for(int i#$; i8$ ;i++)for( int >#$; >81$$; >++)a[i][>]#1$$;&) for(int i#$; i81$$ ;i++)for( int >#$; >8$; >++)a[>][i]#1$$;
Shich of the a&o'e 2 codesexecutes Luic"y.
ans: a-code ta2es +*+*
comparisons and +*+*increments and b-codeta2es +** comparisonsand +** increments.Fo a-code executes3uic2ly which is havingouter loop count less1
. i) (*ptr)++;ii) *ptr+#1;iii) *ptr++;
which of the fo"owin is sae.
ans: i1 and ii1 are same
. 'oid ain(){char *s#3susan3;c"rscr();printf(s);etch();}
ans: susan
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
52/123
C. 'oid ain(){int a[2$];c"rscr();*a#(int*)a""oc(siEeof(a));printf(3,d3-siEeof(a));
etch();}
ans: error nonportablepointer conversion1
$. 'oid ain(){'oid fun(int-int);int i ->;i#2->#!;fun(i++->++);printf(3,d ,d3-i->);etch();}
'oid fun(int i-int >){i66/66&}
ans: , ! no syntax errorin function as it is a comma operator1
1. 'oid ain(){int ctr#$;c"rscr();switch(ctr){
case $:ctr++;case 1:ctr++;
defau"t :ctr++;};printf(3,d3-ctr);etch();}
ans: ,
2. 7define putchar(c) printf(3,c3-c);
ain(){int c#6C;putchar(c);}
ans: E
!. ain(){
printf(3,d3-printf(3%5R3));}
ans: ABLJJ+
. ain(){
int i#6;printf(3,d3-func(i));}
int func(int r){int static resu"t;if(r8#$) resu"t#1;e"seresu"t#func(rO!)+func(rO1);return resu"t;}
ans: ,
. ain()
{int i#!;whi"e(iOO){int i#1$$;iOO;printf(3,d..3-i);}}
ans: HH..HH..HH..
6. 7define putchar(c) printf(3,c3-c)'oid ain()
{char s#4c4;putchar (s);}
ans: c
. Zdefine putchar c1printf"=c"/c1
'oid ain(){char s#4c4;putchar (s);}
ans: error gap shouldnot be there between putchar andc1 1
. 'oid ain(){int a[]#{C--1--};int *p;p#@a[!];printf(3,d3-p[O1]);
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
53/123
}
ans:
C. 'oid ain(){int a[]#{1$-2$-!$-$-$};
int *p;p# (int*)((char *)a +
siEeof(int));printf(3,d3-*p);}
ans: (*
C$. Shich code wi"" run faster
for(i#$;i81$$;i++)for(>#$;>81$;>++)a[i][>]#$;
VH
for(>#$;>81$;>++)for(i#$;i81$$;i++)a[i][>]#$;
ans: first code **increments ** comparisons1
second code** increments **comparisons1
second code will runfaster which is having outerloop count less1
$$. ain() {'oid print(int);int i#;print(i);}'oid print(int n){if(n9$){print(nO1);printf(3,d3-n);print(nO1);}}
ans:(,(!(,(+(,(!(,(
$1. int * f(int a){int i;i#a;
return(@i);}
ans: we can't return address ofauto variable as itis allocation is made in stac2which is deallocated
when the function returns.
$2. (1)Jo find strin "enth &y usinrecursi'e function.(2)Jo find fi&onaci series &y usinrecursi'efunction.(!)Jo write code for a""oc so thata""ocation ay &eade fast"y.()Srite a fn prototype whichreturn a pointer whichpoints to an array of 1$ ints.
ans: int #f11?*@
$!. 'oid ain (){int
a[]#{1$1-2$1-!$1-$1-$1-6$1-$1-$1-C$1-$$1};
int *p; c"rscr ();printf(3,d 3-a);printf(3arthi 3);printf(3,d 3- ((char *)a +
siEeof(int)));p#(int *) ((char *) a +siEeof
(int));printf(3,d3-*p);
}
ans: M)M! arthi M)M)(* address of a $ M)M!1
$. 'oid ain (){int
a[]#{1$1-2$1-!$1-$1-$1-6$1-$1-$1-C$1-$$1};
int *p; c"rscr ();printf(3,d 3-a);printf(3arthi 3);printf(3,d 3- ((char *)-a+
siEeof(int)));
p#(int *) ((char *) a +siEeof(int));
printf(3,d3-*p);}
ans: error illegal use ofpointer1
$. ain (){
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
54/123
inta[1$]#{1$-C---6---!-2-1};
c"rscr();int #p$a&int #3$a?7@&printf(3,d ,d 3-L-p);}
ans: error declarationis not allowed heresince clrscr1 function isthere. 4eclarationshould come before anyexecutable statement1
$6. ain(){
printf(3,d3-printf(3Me""oUoft3));}
ans: 5elloFoftH
$. ain(){int i#!;printf(3,d ,d ,d3-i++-i-+
+i);}
ans: ! ! !
$. ain(){int i#1$;int >-#;
int a[1$];for(>#$;>81$;>++)a[>]#(i+)+(i*);}VptiiEe the a&o'e code.
ans: main19int
i$*/2$+//a?*@&
for$*&;*&661a?@$)+&>
$C. ain(){int *p#$x1$$;int *L#$x1$$;int #p*L;printf(3,xDn3-);}
ans: error pointermultiplication is notvalid1
1$. Rhar* foo(Utr...){
char str[];
strcpy(str-3Me""oUoft3); return str; }
ans: we can't returnaddress of auto variableas itis allocation is made instac2 which isdeallocatedwhen the functionreturns.
11. int a[1$][2$][!$][$];int *p
Mow to access an e"eent of ausin p?
ans: a?i@?@?2@?l@ #p6
12. ain(){int i#1$;if(i92$)if(i##1$)printf(3Mi3);e"seprintf(35ye3);}
ans: no output
1!. 0f a row dainated two dientiona"arry in the fo""owin which one isad'antaeand why?
a) for(i#$;i81$$$;i++)for(>#$;>81$$$;>++)tep#tep+a[i][>];
&) for(>#$;>81$$$;>++)for(i#$;i81$$$;i++)
tep#tep+a[i][>]
ans: a ust it is a guess.n Ia% we are accessingelements which are inadacent locations. n Ib%we are accessingelements which are*** locations apart1
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
55/123
1. 'oid ain(){printf(3,d3-(f"oat)!2);}
ans: *
1. 'oid ain(){char *s#3Me""o Sor"d3;printf(3,c3-s);}
ans: garbage character
16. 'oid ain(){char *s#3Me""o Sor"d3;printf(3,c3-*s);}
ans: 5
1. fp-fs;fp#fopen(3tc.dat3-3w3);fs#fopen(3tc.dat3-3w3);putch(4%4-fp);putch(454-fs); Shat wi"" happen?
ans: A is overwritten byB
1. Shat is the eLui'a"ent of a[i]ans: #a6i1
1C. int #func1int/int1is a pointer to
a function with 2 inteers asparaeters and returnin aninteer 'a"ue.
2$. int ##func1int #/int #1is apointer to a function with 2 inteerpointers as paraeters andreturnin a pointer to an inteer
21. switch(f"oat 'a"ue)
ans: compiler error
22. ain(){
int a[]#{1-2-!--};int *p#a+1;int *L#a+;int dif#LOp;printf(3,d3- dif);}
ans: !
2!. switch(IW)
ans: case *: will beexecuted.
2. 7define exp ain()
{printf(3,d3-exp++);
}
ans: lvalue re3uired
2. strcat(str-str);ans: compilation errordestination stringlength shouldaccommodate both thestrings1
26. int#ptr1?*@
ans: pointer to array of* integers.
2. int ain(){char *str # 3Me""o- wor"d3 ;printf(3,s3 - str);}
ans: 5ello/ world whenthe field width is lessthan the length of thestring the entire stringis printed1
2. int #ptr?*@&
ans: declaration of *pointers
2C. int ain(){extern int i;printf(3,d3 - i);}
ans: lin2er error
!$. 'oid tep();'oid tep('oid);int ain()
{tep();}'oid tep(){printf(3R is excitinP3);}
ans: L is exciting
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
56/123
!1. 'oid tep();'oid tep('oid);int ain()
{tep();}'oid tep('oid)
{printf(3R is excitinP3);}
ans: L is exciting
!2. 'oid tep();'oid tep('oid);int ain()
{tempvoid1&}'oid tep(){printf(3R is excitinP3);
}
ans: compiler errorsyntax error1
!!. 'oid tep(int i){if(i ## 1$) return;i++ ;tep(i);printf(3,d 3 - i);}
int ain(){
tep(1);}
ans: * H M 7 ) + ! , (
!. soe Luestion on 3strto3 function
!. int ain(){char *str # 3Me""o- wor"d3;int i $ si0eofstr1&for( ; i 9# $ ; iOO)printf(3,c3 - str[i]);}
ans: olle5 si0eofpointer is ! bytes1
!6. int ain(){int a #
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
57/123
int x#12;printf(3Dn,d3-1+x++);}
ans: (H
!. ain()
{/0 *f1;/0 *f2;f1#fopen(3yfi"e3-3w3);f2#fopen(3yfi"e3-3w3);fputc(4%4-f1);fputc(454-f2);fc"ose(f1);fc"ose(f2);}
what does f1 n f2 conatins?
ans: B
. if ip is code friday monday
sundayin coad "ine thenain(int arc-char *ar'[])
{printf(3Dn,c3-**++ar');}
ans:may be f
. 7define ax 1$ain()
{printf(3Dn,d3-ax++);}
ans: error lvaluere3uired1
6. ain(){int
a[]#{1-2-C--6-!----C};int *p#a+1;int *L#a+6;printf(3Dn,d3-LOp);}
ans: +
. ain(){int i#!;whi"e(iOO){int i#1$$;iOO;printf(3,d 3-i);}}
ans: HH HH HH
. what does (*a)[1$] eans?
ans: a is pointer to anarray of * integers
C. Vpen a fi"e 3input3 and print theodd nu&er of "ines first on the screen andthen
e'en nu&er of "ines..soethin"ie that.....
$. ain(){int x#- y;y# x*x++ * ++x ;printf(3,d ,d3-x-y);}
ans: 7 ()
1. ain(){int a#1$-whi"e(OO&9#$ @@ ++a){OO&;++a;}printf(3,d ,d3-a-&);}
ans: ) -(
2. ain()
{char i;for (i#$; i8#2; i++){printf(3,c3- i);}}
ans: infinite loop signed char range is -(M to (71
!. ain(){int i#$;switch(i)
{case 1: printf(3hi3);case $: printf(3Eero3);case 2: printf(3wor"d3);}}
ans: 0eroworld
. struct ===
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
58/123
{int a:6;float b:!&char s;}structure;
ain(){
printf(3,d3-siEeof(structure));}
ans: error bit fieldsmust be signed or unsigned int1
. struct ==={int a:6;*f"oat &:;*char s;}structure;
ain(){
printf(3,d3-siEeof(structure));}
ans: (
6. struct ==={int a:)&*char s;*}structure;
ain(){
printf(3,d3-siEeof(structure));}
ans:
. struct ==={int a&char s;}structure;
ain(){
printf(3,d3-siEeof(structure));}
ans: ,
. ain(){char *s;s#3hot >a'a3;strcpy(s-3so"aris >a'a3);printf(3,s3-s);}
ans: solaris ava extralocations will be overwritten1
C. ain(){char #p$'a'&
int #i$**J #p&printf(3,d3-i);}
ans: error nonportablepointer conversion1
6$. ain(){int n#;printf(3Dnn#,*d3-n-n);}
ans: n$ + widthspecifier =+d right ustified1
61. Mow "on the fo""owin prorawi"" run?
ain(){printf(3DnUonata Uoftware3);ain();}
ans: until the stac2overflows
62. ain(){
const int x#;int *ptrx;ptrx#@x;*ptrx#1$;*x#1$;*printf(3,d3-x);}
ans: * you can changea constant obect by using a pointer1
6!. ain(){const int x#;int *ptrx;
ptrx#@x;*ptrx#1$;x#1;printf(3,d3-x);}
ans: error cannotmodify a constant obect1
6. ain()
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
59/123
{const char *fun();#fun1$"A"&}
const char *fun(){return 3Me""o3;
}
ans: error cannotmodify a constantobect1 fun1 returns toa "const char" pointerwhich cannot bemodified
6. Shat error wou"d the fo""owinfunction i'e on copi"ation?
f(int a- int &){int a;a#2$;
return a;}
ans: error redeclarationof a1
66. Sou"d the fo""owin proracopi"e?
ain(){int a#1$-*>;'oid *; >##@a;>++;266&
printf(3Dn,u,u3->-);}
ans: o/ the arithmeticoperation is notpermitted on voidpointers. Fi0e of thetype is un2nown.
6. 0n the fo""owin prora how wou"dyou print $ usin p?
ain(){int a[]#{1$- 2$- !$- $-
$};
char *p;p# (char*) a;}
ans:printf"=d"/#int#1p6!11& orprintf"=d"/#p6M11&
6. Goint out the error in the fo""owinprora
ain(){int a#1$;'oid f();a$f1&printf(3Dn,d3-a);}
'oid f(){printf(3DnMi3);}
ans: error not anallowed type1. Gheprogram is trying tocollect the value of a"void" function into aninteger variable.
6C. 0f the fo""owin prora (ypro)is run fro the coand "ine asmyprog friday tuesday sunday-
Shat wou"d &e the output?ain(int arc- char *ar'[])
{whi"e(siEeof(ar'))printf(3,s3-ar'[OO
siEeof(ar')]);}
ans:
$. 0f the fo""owin prora (ypro)is run fro the coand "ine asmyprog friday tuesday sunday-Shat wou"d &e the output?
ain(int arc- char *ar'[]){printf(3,c3-*++ar'[1]);}
ans: r chec2 it out1
1. 0f the fo""owin prora (ypro)is run fro the coand "ine asypro friday tuesday sunday-Shat wou"d &e the output?ain(int arc- char*ar'[])
{printf(3,c3-**++ar');}
ans: f chec2 it out1
2. ain(){char near * near *ptr1;char near * far *ptr2;char near * hue *ptr!;printf(3,d ,d
,d3-siEeof(ptr1)-siEeof(ptr2)-siEeof(ptr!));
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
60/123
}
ans: ( ! !
!. Shat is the difference &etween thefo""owin dec"arations?
const char *const s; char const
*const s;
ans. o difference
. Shat is the difference &etween thefo""owin dec"arations?
const char *s;char const *s;
ans. o difference
. ain(){int y#12;const int x; x#y;
printf(3,d3-x);}
ans: error cannotmodify a constant obect1
6. ain(){int y#12;const int x#y;printf(3,d3-x);}
ans: (M when not
initiali0ed const variable will havegarbage value1
. ain(){const int x;x#12;printf(3,d3-x);}
ans: error cannotmodify a constantobect. x should havebeen initiali0ed where itis declared1
. 0n the fo""owin code- is p2 aninteer or an inteer pointer?
typedef int# ptrptr p/p(&
ans. nteger pointer
C. 0f the fo""owin prora (ypro)is run fro the coand "ine as
myprog monday tuesdaywednesday thursday-
Shat wou"d &e the output?ain(int arc- char *ar'[])
{whi"e(OOarc 9$)printf(3,s3-*++ar');
}
ans: monday tuesdaywednesday Ghursday
$. 0f the fo""owin prora (ypro)is run fro the coand "ine asypro 1 2 !- Shat wou"d &e theoutput?ain(int arc- char *ar'[])
{int i->#$;for(i#$;i8arc;i++)>#>+ atoi(ar'[i]);printf(3,d3->);
}
ans: chec2 out
1. 0f the prora (ypro) is run frothe coand "ine as ypro 1 2! - Shat wou"d &e the output?ain(int arc- char *ar'[])
{int i;for(i#$;i8arc;i++)printf(3,s3-ar'[i]);}
ans: L:
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
61/123
{/V%JGJH a-&;$.$;}
ans: b is a float variableno error1
. typedef float# KOAGPGD&ain()
{/V%JGJH a-&;b$*.*&}
ans: error illegal use offloating point. 5ere b isa floating pointervariable. Observe thedifference betweenmarco and typedef in+M! and +M+ problems1
6. 7define U_H(x) (x*x)ain()
{int a-!;a# U_H(&+2);printf(3,d3-a);}
ans:
. ain(){int i#;
switch(i){defau"t:printf(3Dn % ouse is an
e"ephant &ui"t &y the \apanese3);case 1:printf(3 5reedin ra&&its is
a hair raisin experience3);&rea;case 2:printf(3Dn /riction is a
dra3);&rea;case !:printf(3Dn 0f practice ae
perfect- then no&ody4s perfect3);}}
ans: A mouse is anelephant built by the]apanese Breedingrabbits is a hair raisingexperience
. 0n the fo""owin code- in whichorder the functions wou"d &e ca""ed?
a# f1(2!-1)*f2(12)+f!();
ans: f/ f(/ f,
C. f!()
{printf(3three 3);return 1;}
f1(int x- int y){printf(3one 3);return(x+y);}
f2(int x){printf(3two 3);return x;}
ain(){int a;a# f1(2!-1)*f2(12)+f!();printf(3,d3-a);}
ans: one two three (
C$. ain(){int a#1$-&;a8# ? $$ : $$;
printf(3Dn,d3-&);}
ans: error lvaluere3uired. Londitionaloperator has highestpriority thanassignment operator1
C1. ain(){int a#1$-&;a8# ? $$ : ($$);printf(3Dn,d3-&);}
ans: (**
C2. ain(){int a#1$-&;a9# ? $$ : ($$);printf(3Dn,d3-&);}
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
62/123
ans: **
C!. ain(){int i#1;switch(i){
case 1:printf(3DnHadioacti'e cats
ha'e 1 ha"fO"i'es3);&rea;case 1*2+:printf(3Dn5ott"e for rent
OinLuire within3);&rea;}}
ans: Dadioactive catshave M half-lives no error1
C. ain()
{int i#2;printf(30#,d i#,d3-++i-+
+i);}
ans: $! i$,
C. ain(){unsined char i#$x$;printf(3i#,d3-i881);}
ans: i$(+)
C6. ain(){unsined char i#$x$;i#i881;printf(3i#,d3-i);}
ans: i$*
C. ain(){int 5#$x////;^B & J#
note: not assigned to B #Jprintf(3,d3-5);}
ans: -
C. ain(){unsined int 5#$x////;X5 ;
printf"=d"/B1&}
ans: -
CC. ain(){
unsined int 5#$x////;X5 ;printf"=u"/B1&}
ans: )++,+
6$$. /unc(int a- int&){int a;a#1$;return a;}wi"" there &e any error?
ans: error redeclarationof a1
6$1. strin is i'en myprog one twothreeShere ypro is an exe fi"e.Shat wi"" the output of thefo""owin prora ?
ain(int arc- char *ar'[]){printf(3,c3++**ar');}
ans: n chec2 it out1
6$2. Zdefine FVDb1 b#b&ain()
{int i#!;printf(3,d3-U_H(i+2));}
ans: error semicolon inmacro definition willcause error when it isreplaced in printfstatement1
6$!. 7define U_H(&) &*&
ain(){int i#!;printf(3,d3-U_H(i+2));}
ans:
6$. ain(){
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
63/123
char c#4a4;printf(3,d ,d3-
siEeof(c)-siEeof(4a4));}
ans: (
6$. ain(){char c#4a4;Printf(3,d ,d3-
siEeof(c)-siEeof(4a4));}
ans: lin2er errorundefined symbol_Printf1
6$6. ain(){Lhar c$'a'&printf(3,d ,d3-
siEeof(c)-siEeof(4a4));
}
ans: error undefinedsymbol ILhar% /undefined symbol Ic% /statement missing & 1
6$. 'oid ain('oid){struct s{int x;f"oat y;}s1#{2-.$$};
union u{int x;f"oat y;}u1;u$union u1s&printf(3,d and
,f3-u1.x-u1.y);}
ans: error incompatibletype conversion1
6$. int fn('oid);'oid print(int-int(*)());
int i#1$;
'oid ain('oid){int i#2$;print(i-fn);}
'oid print(int i-int (*fn1)()){
printf(3,dDn3-(*fn1)());}
int fn('oid){return(iO#);}
ans: +
6$C. 'oid ain('oid){char nu&ers[]
[6]#{3ero3-3Vne3-3Jwo3-3Jhree3-3/our3};printf(3,s is
,c3-@nu&ers[][$]-nu&ers[$][$]);}
ans: our is `
61$. 'oid ain('oid){
int y-E;int x$y$0$*&int f#x;f"oat ans#$.$;f *#x*y;ans#x!.$+y!;printf(3,d ,.2f3-f-ans);}
ans: *** ).,,
611. dou&"ed&"#2$.!$-d#.1$-d&"'ar!;
'oid ain('oid)
{dou&"e d&"n('oid);d&"'ar!#d&"n();printf(3,.2fDt,.2fDt
,.2fDn3-d&"-d-d&"'ar!);}
dou&"e d&"n('oid){dou&"e d&"'ar!;d&"#d&"'ar!#.;return(d&"+d+d&"'ar!);}
ans: !.+* !.+7,.+7
612. 'oid ain('oid){int o"d'ar#2-new'ar#O2;int swap(int-int);swap(o"d'ar-new'ar);printf(3Iu&ers are ,dDt
,d3-new'ar-o"d'ar);}
int swap(int o"d'a"-int new'a")
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
64/123
{int tep'a"#o"d'a";o"d'a"#new'a";new'a"#tep'a";}
ans: umbers are -(+ (+
61!. 'oid ain('oid){int i#1$$->#2$;i++ #>;i*#>;printf(3,dDt,dDn3-i->);}
ans: error lvaluere3uired1
61. int new'a"(int);'oid ain('oid)
{
int ia[]#{12-2--$};int i;int su#$;for(i#$;ia[i];i++){su+#new'a"(ia[i]);}printf(3Uu# ,d3-su);}
int new'a"(int x){static int di'#1;return(xdi'++);}
ans: Fum$ ,H
61. 'oid ain('oid){int 'ar1-'ar2-'ar!-inax;'ar1#;'ar2#;'ar!#6;minmax$varvar(1X
varvar,1Xvar:var,:var(var,1Xvar(:var,&
printf(3,dDn3-inax);}
ans: ) maximum ofthree numbers1
616. static int i#$;int print(int i);'oid ain('oid)
{static int i#1$$;whi"e(print(i)){
printf(3,d 3-i);iOO;}}
int print(int x){static int i#2;
return(iOO);}
ans: ** HH
61. 'oid ain('oid);typedef struct IJype
{int i;char c;"on x;}IewJype;
'oid ain('oid){
IewJype *c;c#(IewJype
*)a""oc(siEeof(IewJype));cO9i#1$$;cO9c#4R4;(*c).x#1$$;printf(3(,d-,c-,d)3-cO
9i-cO9c-cO9x);}
ans: **/L/ **1
61. ain(){
char *p1#3Iae3;char *p2;p2#(char *)a""oc(2$);whi"e(*p2++#*p1++);printf(3,sDn3-p2);}
ans: an empty string nooutput1
61C. ain(){int x#2$-y#!;x # y++ + x++;y # ++y + ++x;
printf(3,d ,dDn3-x-y);}
ans: +7 H!
62$. ain(){int x#;printf(3,d ,d
,dDn3-x-x882-x992);
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
65/123
}
ans: + (*
621. 7define swap1(a-&) a#a+&;aO&;a#aO&;
ain()
{int x#-y#1$;swapx/y1&printf(3,d ,dDn3-x-y);swap2(x-y);printf(3,d ,dDn3-x-y);}
int swap2(int a-int &){int tep;tep#a;a;a#tep;return;}
ans: * +* +
622. 7define swap1(a-&) a#a+&;aO&;a#aO&;
ain(){int x#-y#1$;swapx/y1printf(3,d ,dDn3-x-y);swap2(x-y);printf(3,d ,dDn3-x-y);}
int swap2(int a-int &){int tep;tep#a;a;a#tep;return;}
ans: * +* +
62!. 7define swap1(a-&) a#a+&;aO&;a#aO&
ain()
{int x#-y#1$;swapx/y1printf(3,d ,dDn3-x-y);swap2(x-y);printf(3,d ,dDn3-x-y);}
int swap2(int a-int &){int tep;
tep#a;a;a#tep;return;}
ans: error statement
missing &1
62. ain(){char *ptr # 3Haco
Uystes3;(*ptr)++;printf(3,sDn3-ptr);ptr++;printf(3,sDn3-ptr);}
ans: Famco Fystemsamco Fystems
62. ain(){char s1[]#3Haco3;char s2[]#3Uystes3;s1#s2;printf(3,s3-s1);}
ans: error lvaluere3uired1
626. ain(){char *p1;
char *p2;p1#(char *) a""oc(2);p2#(char *) a""oc(2);strcpy(p1-3Haco3);strcpy(p2-3Uystes3);strcat(p1-p2);printf(3,s3-p1);}
ans: DamcoFystems
62. ain(){int x#1$-y#1;x#x++;
y#++y;printf(3,d ,dDn3-x-y);}
ans: )
62. ain(){int a#$;
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
66/123
if(a#$) printf(3HacoUystesDn3);
printf(3Haco UystesDn3);}
ans: Damco Fystems
62C. ain(){int a#$;if(a##$) printf(3Haco
UystesDn3);printf(3Haco UystesDn3);}
ans: Damco FystemsDamco Fystems
6!$. int Uu"eent(int *-int);'oid ain('oid)
{int x[1$];
int i#1$;for(;i;){iOO;*(x+i)#i;}
printf(3,d3-Uu"eent(x-1$));}
int Uu"eent(int array[]-int siEe){int i#$;f"oat su#$;for(;i8siEe;i++)
su+#array[i];return su;}
ans: !+
6!1. int printf(const char*-...);'oid ain('oid)
{int i#1$$->#1$-#2$;int su;f"oat a'e;char yforat[]#3a'e#
,.2f3;su#i+>+;
a'e#su!.$;printf(yforat-a'e);}
ans: ave$!,.,,
6!2. 'oid ain('oid){int a[1$];
printf(3,d3-((a+C) +(a+1)));
}
ans: error invalidpointer addition1
6!!. int &as[]#{2$--2$-!-2$};'oid ain('oid)
{int pos#-*next();*next()#pos;printf(3,d ,d
,d3-pos-*next()-&as[$]);}
int *next(){int i;for(i#$;i8;i++)if (&as[i]##2$)return(&as+i);printf(3rrorP3);
exit($);}
ans: + (* +
6!. static int i#;'oid ain('oid)
{int su#$;do{su+#(1i);}whi"e($8iOO);}
ans: error divide by0ero exception1
6!. 'oid ain('oid){'oid pa(int *a-int n);int arr[]#{--!-2-1};pa(arr-);}
'oid pa(int *a-int n){int i;for(i#$;i8n;i++)printf(3,d 3-*(a++)+i);
}
ans: + + + + +
6!6. const int #1$$;'oid ain('oid)
{int a[1$$];int su#$;for(#$;81$$;++)
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
67/123
*(a+)#;su+#a[OO];printf(3,d3-su);}
ans: error cannotmodify a constant obect1
6!. int #1$$;'oid ain('oid)
{int a[1$$];int su#$;for(#$;81$$;++)*(a+)#;su+#a[OO];printf(3,d3-su);}
ans: HH
6!. ain()
{printf(3Me""o
,d3-printf(3_W%HT test? 3));}
ans: VWADC testX 5ello(
6!C. ain(){int i->-%;for (% # O1;%8#1; %++)printf(3,d 3-PP%);}
ans: *
6$. ain(){int i#2;printf"=d
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
68/123
ans. static
6. int *func(){static int x#$;x++; return @x;
}int ain()
{int * y # func();printf(3,d 3-(*y)++);func();printf(3,d3-*y);return $;}
ans: ,
6C. 'oid ain(){unsigned int x$ -&
int y #$;if(y8#x) printf(3% is
trueDn3);if (y ##(x # O1$)) printf(35
is trueDn3);if ((int) x9#y) printf(3R is
trueDn3);}
ans: A is true
6$. 'oid ain(){int x$ -&
int y #$;if(y8#x) printf(3% istrueDn3);
if (y ##(x # O1$)) printf(35is trueDn3);
if ((int) x9#y) printf(3R istrueDn3);
}
ans: no output
61. 'oid ain(){unsined int x# O1;int y #$;
printf"=d "/x1&if(y8#x) printf(3% is
trueDn3);if (y ##(x # O1$)) printf(35
is trueDn3);if ((int) x9#y) printf(3R is
trueDn3);}
ans: - A is true =dsigned integer specifier1
62. 'oid ain(){unsined int x# O1;int y #$;
printf"=u "/x1&if(y8#x) printf(3% is
trueDn3);if (y ##(x # O1$)) printf(35
is trueDn3);if ((int) x9#y) printf(3R is
trueDn3);}
ans: )++,+ A is true =uunsigned integer specifier1
6!. 0n the fo""owin code what is thecorrect way to increent the 'aria&"e ptrto
point to the next e&er of thearray
union intf"oat{int int%rray[ ];f"oat f"oat%rray[ ];};
union intf"oat arr[2$];'oid *ptr #arr;
ans: ptr $ void#1unionintfloat#1ptr 61&
6. 7define GH0IJ=Y(x-y-E) printf (7x3#,dDt3 7E 3#,dDn3- x- y)'oid ain()
{int x- y- E;x#$; y#1; E#2;
x ++y ++E;GH0IJ=Y(x-y-E);
++x ++y @@ ++E;GH0IJ=Y(x-y-E);
++x @@ ++y ++E;GH0IJ=Y(x-y-E);
}
ans:x$* 0$(x$ 0$(x$( 0$,
6. ain(){
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
69/123
printf(3,d ,d3-siEeof(IW)- siEeof(33));
}
ans: ! WKK is apointer so it ta2es !bytes. si0eof empty
string is 1
66. int *chec(int-int);'oid ain()
{int c-d;c $ chec2/(H1&d$ chec2(*/,*1&printf(3Dnc#,u3-c);}
int * chec(int i-int > ){int *p- *L;p#@i;L#@>;
if(i9#C)return(L);e"sereturn(p);}
ans: nonportablepointer conversion
6. 'oid ain(){int a[!][2]#{ 1----6-};printf(3,d3-((a+1)O
(@a+1)));
}
ans: 8(. haven%t beenable to figure this oneout. a is the address ofthe (-d array/ here a/a/ #a all give the samevalue/ i.e./ address ofthe array. a61 givesthe address of thesecond row/ it is thesame as a?@. #a61gives the address of thefirst cell of the secondrow. ##a61 gives the
value of the elementstored in the first cell inthe second row.#a6161 gives theaddress of the secondcell of the second row.##a6161 gives thevalue of the elementstored in the second cellin the second row.
6. 'oid ain(){int a[!][2]#{ 1----6-};printf(3,d 3-a);printf(3,d 3-@a);printf(3,d 3-*a);
}
ans: M)M( M)M( M)M( allare same1
6C. ain(){char str1[]#3Me""o3;char str2[]#3Me""o3;if(str1##str2 @@
(*(str1+6)## *(str2+6)) )printf(3Dn Lua"3);e"seprintf(3Dn uneLua"3);}
ans: une3ual
66$. ain(){int a- -c#12;a#X&;c#cK(Xa @ &$);c#cK(X(X&));printf(3,dDn3-c);}
ans: (7
661. 7define f(a-&) a+&7define (x-y) x*yain()
{int i;i#f(-(-6));printf(3,d3-i);}
ans: ,!
662. ain(){int i->#CCCC;char &uff[];
i#sprintf(&uff-3,d3->);printf(3,d ,s3-i-&uff);}
ans: ! HHHH
66!. ain(){int i->#CCCCC;char &uff[];
-
8/10/2019 1000 C PROGRAMMING QUESTIONS
70/123
i#sprintf(&uff-3,d3->);printf(3,d ,s3-i-&uff);}
ans: ) -,*7,
66. ain()
{int 0#2;int >#!;int #;printf(3,d3-(08>8));}
ans:
66. 7define acro(a) ((a++) + (++a)+ (a++))
ain(){printf