Top Banner
1. What is the output of the program given below #include<stdio.h> main() { char i=0; for(;i>=0;i++) ; printf("%d\ n",i); } ------------------------------------------------------------------------ --------------------------------------------------------- 2. What is the output of the following program #include<stdio.h> main() { int i=0; fork(); printf("%d",i++); fork(); printf("%d",i++); fork(); wait(); } ------------------------------------------------------------------------ --------------------------------------------------------- 3. What is the memory allocated by the following definition ? int (*x)[10]; 20 bytes,array of pointers ------------------------------------------------------------------------ --------------------------------------------------------- 4. What is the memory allocated by the following definition ? int (*x)(); 2 bytes,pointer to a function ------------------------------------------------------------------------ --------------------------------------------------------- 5. In the following program segment #include<stdio.h> main() { int a=2; int b=9; int c=1; while(b) { if(odd(b)) c=c*a; a=a*a; b=b/2; } printf("%d\n",c); } How many times is c=c*a calculated? ------------------------------------------------------------------------ -------------------------------------------------------- 6. In the program segment in question 5 what is the value of a at the end of the while loop? ------------------------------------------------------------------------ -------------------------------------------------------- 7. What is the output for the program given below typedef enum grade{GOOD,BAD,WORST,BAD}; cant define twice(BAD) main() { BAD g1; g1=1; printf("%d",g1); } ans: error ------------------------------------------------------------------------ -------------------------------------------------------- 8. Give the output for the following program. #define STYLE1 char main() { typedef char STYLE2; STYLE1 x; STYLE2 y; clrscr(); x=255; y=255; printf("%d %d\n",x,y);} ans: -1 -1 bcoz it is char ------------------------------------------------------------------------ ------------------------------------------------------ 9. Give the output for the following program segment. #if def TRUE int I=0; #endif main() { int j=0; printf("%d %d\n",i,j); } ans 0 0 ------------------------------------------------------------------------ ------------------------------------------------------- 10. In the following program #include<stdio.h>main(){ char *pDestn,*pSource="I Love India"; pDestn=malloc(strlen(pSource)); strcpy(pDestn,pSource); printf("%s",pDestn); free(pDestn); }(a)Free() fails (b)Strcpy() fails (c)prints I love India (d)error ans c ------------------------------------------------------------------------ ------------------------------------------------------- 11. What is the output for the following program
146

c_test

Nov 14, 2014

Download

Documents

api-26090714

Complete C questions from all websites
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: c_test

1. What is the output of the program given below#include<stdio.h> main() { char i=0; for(;i>=0;i++) ; printf("%d\n",i); }---------------------------------------------------------------------------------------------------------------------------------2. What is the output of the following program #include<stdio.h>   main() { int i=0;  fork();  printf("%d",i++);  fork(); printf("%d",i++); fork(); wait(); }---------------------------------------------------------------------------------------------------------------------------------3. What is the memory allocated by the following definition ? int (*x)[10]; 20 bytes,array of pointers---------------------------------------------------------------------------------------------------------------------------------4. What is the memory allocated by the following definition ? int (*x)(); 2 bytes,pointer to a function---------------------------------------------------------------------------------------------------------------------------------5. In the following program segment #include<stdio.h> main() { int a=2; int b=9; int c=1; while(b) { if(odd(b)) c=c*a; a=a*a; b=b/2; } printf("%d\n",c); } How many times is c=c*a calculated?--------------------------------------------------------------------------------------------------------------------------------6. In the program segment in question 5 what is the value of a at the end of the while loop?--------------------------------------------------------------------------------------------------------------------------------7. What is the output for the program given below      typedef enum grade{GOOD,BAD,WORST,BAD}; cant define twice(BAD)     main() { BAD g1; g1=1; printf("%d",g1); } ans: error --------------------------------------------------------------------------------------------------------------------------------8. Give the output for the following program. #define STYLE1 char   main() { typedef char STYLE2; STYLE1 x; STYLE2 y; clrscr(); x=255; y=255;printf("%d %d\n",x,y);} ans: -1 -1 bcoz it is char------------------------------------------------------------------------------------------------------------------------------9. Give the output for the following program segment.#if def TRUE int I=0; #endif main() { int j=0; printf("%d %d\n",i,j); } ans 0 0-------------------------------------------------------------------------------------------------------------------------------10. In the following program #include<stdio.h>main(){ char *pDestn,*pSource="I Love India"; pDestn=malloc(strlen(pSource)); strcpy(pDestn,pSource); printf("%s",pDestn); free(pDestn); }(a)Free() fails (b)Strcpy() fails (c)prints I love India (d)error ans c-------------------------------------------------------------------------------------------------------------------------------11. What is the output for the following program     #include<stdio.h>       main(){ char a[5][5],flag; a[0][0]='A'; flag=((a==*a)&&(*a==a[0]));      printf("%d\n",flag);} ans: 1--------------------------------------------------------------------------------------------------------------------------------12. main(){ int i; i=(2,3); printf("%d",i); } a)2 b)3 c)Compiler error d)Syntax error. ans : 3--------------------------------------------------------------------------------------------------------------------------------13 main(){ char str[]="GESL"; printf("%d %d",sizeof(str),strlen(str)); } a)5,5 b)4,4 c)5,4 d)4,5 ans: 5, 4---------------------------------------------------------------------------------------------------------------------------------14. main(){ int i ; for(i=0;i++;i<100) printf("hello world\n"); }a)100 times b)0 times c)Infinite loop d)None of the above. ans: 0 times.--------------------------------------------------------------------------------------------------------------------------------15. main(){ for(i=1;i++;i<100) printf("hello world\n"); }a)100 b)0 times c)Infinite loop d)None of the above. ans: infinite loop --------------------------------------------------------------------------------------------------------------------------------16 main(){ char c; scanf("%s",c); } a)Compiler dependent b)unpredictable c)Compiler error d) scans the i/p. ans: Compiler dependent.--------------------------------------------------------------------------------------------------------------------------------17. main(){int k=5; for(++k<5 && k++/5 || ++k<8); printf("%d\n",k);}a)5 b)6 c)7 d)8 ans: 7--------------------------------------------------------------------------------------------------------------------------------18. main(){ int *ptr1,*ptr2; ptr1=(int *)malloc(sizeof(int)); ptr2=func(20,10,ptr1); printf("%d %d\n",*ptr1,*ptr2); } int *func(int a, int b, int *c) { int x=a+b; *c=a-b; return(&x); }a)Bug in the code. b)No Bugs prints correctly c)Error d) None of the above. Ans: Bug in the code.-------------------------------------------------------------------------------------------------------------------------------19. int main() {int i = 10, j ; if ( ( j = ~i ) < i ) printf ( "True" ) ; else printf ( "False" ) ; } a) True b) False c) Compiler Dependent d) None of the above. ans : False------------------------------------------------------------------------------------------------------------------------------20. How many bytes are required to create a 3*3 matrix using double pointer ans: 12-------------------------------------------------------------------------------------------------------------------------------21. take int=4,float=8,char=1;main() {FILE *fp;printf("%d\n",sizeof(fp) ); } a)2 b)4 c)Compiler dependent d)Error Ans:4------------------------------------------------------------------------------------------------------------------------------

Page 2: c_test

22. main(){ int a=10,20; a^=b^=a^=b; printf("%d\n %d\n",a,b);} a)a=20,b=10 b)a=10,b=20 c)Syntax error d)Unpredictable Ans : a=20 b=10------------------------------------------------------------------------------------------------------------------------------23. main() {int i=10; switch(i) { case 10: printf("Hello "); { case 1 : printf("World "); } case 5: printf("Hello World "); } } a) Hello b) Hello c) Hello World Hello World d) Syntax Error. Ans : Hello World Hello World-----------------------------------------------------------------------------------------------------------------------------

24. main() {char str1[]="Hello"; char str2[]="Hello"; if ( str1==str2 ) printf("True\n"); else printf("False\n"); }a)True b)False c)Error d) Unpredictable. Ans: False.-----------------------------------------------------------------------------------------------------------------------------25. main(){ # include <stdio.h> int i = 10 ; printf("%d\n", i/2 ); } a)10 b)5 c)error d) warning. ans : b-----------------------------------------------------------------------------------------------------------------------------26. #include <stdio.h> # pragma pack(2) struct SIZE { int i; char ch ; double db ; } ; main () { printf ( "%d\n",sizeof(struct SIZE) ); } a)12 b)14 c)16 d)8--------------------------------------------------------------------------------------------------------------------------------27)main() { int arr[]={ 1,2,3,4 }; int *ptr ;;;; ptr++ = arr; printf("%d,%d",ptr[2],arr[2]);return 0; }what is the output :a> compile time error :multiple termination statements for pointerb> lvalue required for ptr c> prints 3 3 d> printd 4 3 ans b: lvalue required for ptr;--------------------------------------------------------------------------------------------------------------------------------28 main() { char s[10]; scanf ("%s",s); printf(s); } what is the output if input is abcd : a> prints abcd b> compiler error c> prints abcd and 6 junk characters d> printd s -------------------------------------------------------------------------------------------------------------------------------29 main() { char c = 255; printf ("%d",c); return 0; } what is the output a> illegal character assignment b> prints –1 c> prints 2 d> prints 255 ans b: prints -1.-------------------------------------------------------------------------------------------------------------------------------30 main() { int i; for (i=7;i<=0;i--) printf ("hello\n"); } what is the output a> prints hello 7 times b> prints hello 8 times c> prints hello once d> prints nothing ans b: prints nothing.-------------------------------------------------------------------------------------------------------------------------------31main() { printf( printf ("world") ); } a> prints world b> prints printf ("world") c> prints nothing d> compiler error ans d: compiler error.-----------------------------------------------------------------------------------------------------------------------------32. What is the output of the following code ?int main( ) { for( ; ;); printf("Hello\n"); return 0; } a. give compilation error b. prints Hello infinite times c. Runs in an infinite loop without printing anything. d. prints Hello once. Ans: c-----------------------------------------------------------------------------------------------------------------------------33. Output of the code? FUNC (int *p) { p = (int *)malloc(100); printf("p:%x",p); } int main( ) { int *ptr; FUNC(ptr); printf("Ptr:%x",ptr); return 0; } a. Both printf statements prints same values. b. Both print different values. c. Gives compile time error. d. Gives run time error. Ans: b-----------------------------------------------------------------------------------------------------------------------------34. Output of the code?int main(){ char a[] = "world"; printf("%d %d\n",strlen(a),sizeof(a)); return 0; } a. 5,5 b. 6,5 c. 5,6 d. 6,6 Ans: c-----------------------------------------------------------------------------------------------------------------------------. 35 What is the output generated? main(){ char *s = "Hello"; printf("%s",1(s)); }a. Hello b. ello c. e d. none of these. Error-----------------------------------------------------------------------------------------------------------------------------36. Interpret the given declaration char ( * ( f ( ) ) [ ] ) ( ) a. f is a pointer to function returning char b. f is a pointer to an array of function returning a char c. Invalid declaration d. f is a function returning pointer to array[] of pointer to function returning char. Ans : d---------------------------------------------------------------------------------------------------------------------------------37 .what is the o/p ? void main(){ char *mess[]={"Have","a","nice","day","Bye"); printf("%d \t %d",sizeof(mess),sizeof(mess[1])); } a. 16 4 b. 5 4 c. 20 4 d. Error ans: c---------------------------------------------------------------------------------------------------------------------------------38.what is the o/p of the following programe?void main() { int i,count=0; char *p1="abcdefghij"; char *p2="alcmenfoip"; for(i=0;i<=strlen(p1);i++) { if(*p1++ == *p2++) count+=5; else count-=3; } printf("count=%d\n",count); } a. 15 b. 6 c. 12 d. compiler error ans:9 ans: b-------------------------------------------------------------------------------------------------------------------------------39.what does main return on successful execution? a. 1 b. 0 c. –1 d.Nonzero ans:b

Page 3: c_test

------------------------------------------------------------------------------------------------------------------------------40 main(int argc,char *argv[]) { printf((argc > 1 ? "%c" : "%c",*++argv); } If the i/p string is "GESL Bangalore". a. G b. E c. B d. GESL ans: c------------------------------------------------------------------------------------------------------------------------------41. How do u declare a pointer to an array of pointers to int? a. int *a[5]; b. int **a[5]; c. int *(*a)[5]; u cannot declare ans: c---------------------------------------------------------------------------------------------------------------------------------42) main(){ int a; char *p; a = sizeof(int) * p; printf("%d\n",a);} a)compile error b)run time errorc)4 d)compiler dependent ans:a---------------------------------------------------------------------------------------------------------------------------------43)#define SIZE sizeof(int) main(){ int i=-1; if( i < SIZE ) printf("True\n"); else printf("False\n"); } a) True b) False c) can't predict d) None of these ans:b---------------------------------------------------------------------------------------------------------------------------------44) int (*fun())[]a) function returning a pointer to an array b) function returning an array of pointers c) pointer to a funtion which takes array as asrument d) Compiler error ans: a---------------------------------------------------------------------------------------------------------------------------------45) main() { int a=8,d; int *p; p=&a; d=a/(*p); print("%d\n",d); }a) 1 b) 0 c) compiler error d) run time error ans: a---------------------------------------------------------------------------------------------------------------------------------46) main(){ char *a="Hello"; *a++ = 'h'; printf("%s\n",a); }a) hello b) ello c) runtime error d) compiler error ans:b---------------------------------------------------------------------------------------------------------------------------------47) main(){ char p[]="Hello"; p[0]='h'; printf("%s\n", p); }a) hello b) Hello c) compiler error d) run time error ans:a---------------------------------------------------------------------------------------------------------------------------------48)#define mysizeof(a) (&a+1) - &a main(){float d; printf("%d\n", mysizeof(d) ); }note: assume sizeof float is 8 bytes a) 8 b) 4 c) 1 d) compiler error ans:c---------------------------------------------------------------------------------------------------------------------------------49) main() { int *p=10; printf("%d\n",*p); }a) 10 b) run time error c) compiler error d) 5 ans:b---------------------------------------------------------------------------------------------------------------------------------50)main(){int i=-1; i<<=2; printf("%d\n",i); }a) –1 b) –2 c) –4 d) 0 ans:c---------------------------------------------------------------------------------------------------------------------------------51) main(){ int i= 0xffffffff; printf("%d\n",i); } note: size of int is 4 bytesa) –1 b) 65635 c) 100 d) error ans:a--------------------------------------------------------------------------------------------------------------------------------52)#include<stdio.h> main() { scanf("%d"); printf(); } which of the following is correct?a)compilation error b)Run time error c)No output d)depends on the compiler ans : a---------------------------------------------------------------------------------------------------------------------------------53)#include<stdio.h> #define islower(c) ('a'<=(c) && (c)<='z') #define toupper(c) (islower(c)?(c)-('a'-'A'):(c))main() { char *p="i am fine"; while(*p) printf("%c",toupper(*p++)); }a)bcd b)AFE c)aFe d)BCd ans : b---------------------------------------------------------------------------------------------------------------------------------54) #include<stdio.h> main() { 200; printf("tricky problem"); }a)warning message b)compilation error c)run time error d)none of these ans : a--------------------------------------------------------------------------------------------------------------------------------55)which is the null statement? a) ; b) {} c) '\0';d)all of these ans : a--------------------------------------------------------------------------------------------------------------------------------56)what is the correct prototype of printf function ? a)printf(char *p,...); b)printf(const *char *p,...); c)printf(const char *p,...); d)printf(const *char p,...); ans : c---------------------------------------------------------------------------------------------------------------------------------57)main(){int *p ; p=(int *)malloc(-10); }a) allocates 0 bytes b) allocates memory, if available c) compilation error d) Runtime error Ans) b---------------------------------------------------------------------------------------------------------------------------------58). main(){ for( printf("a") ; printf("b") ; printf("c") ) ; }a) abc b) abc abc abc .....(infinite times) c) a bc bc bc ....(infinite times) d) Error Ans) c---------------------------------------------------------------------------------------------------------------------------------59) main() { int i= 10 * fun() ; printf("%d",i); } fun(){return 10 ; } a) 0 b) 10 c) 100 d) Error Ans) c---------------------------------------------------------------------------------------------------------------------------------60). int i= 10 * fun(); main(){printf("%d",i); } fun() {return 10 ;}

Page 4: c_test

a) 0 b) 10 c) 100 d) Error Ans) d---------------------------------------------------------------------------------------------------------------------------------61). Assume size of int to be 2 bytes : main(){int i = 100 ; printf("%d ", sizeof(i++));printf("%d ",i) ;}a) 2 100 b) 2 101 c) 100 101 d) 101 100 Ans) abcoz sizeof operator does effect the i++;--------------------------------------------------------------------------------------------------------------------------------62) main(){ int A=1,B=2;if(A==B < printf("Hello ")) printf("world\n"); else printf("Bangalore\n"); } What is the o/p? a> world b> Hello bangalore c> bangalore d> Hello world. ans > d> Hello world.--------------------------------------------------------------------------------------------------------------------------------63)main() { int i; for(i=0; i< 10; i++){ int j=10; j++;printf("j= %d\n", j);}} what is o/p ?a> 10 to 19 b> error j undeclared c> 10 times 11 d> 10 – 18 ans> c> 10 times 11.---------------------------------------------------------------------------------------------------------------------------------64) union test{ int a; union test *p; }; main(){ union test q; printf(" a= %d\n ", q.a); } what is o/p?a> 0 b> syntax error c> garbage value d>run time error ans > c---------------------------------------------------------------------------------------------------------------------------------65)register int a,b; main(){ for(a=0 ; a<5 ; a++) b++; } a> 5 b> 4 c> 0 d> error ans > d---------------------------------------------------------------------------------------------------------------------------------66) # define dprint(expr) printf(" expr= %d \n ", expr)main(){ int i=10,j=2;dprint(i / j) ;} a> 5 b > expr= 5 c> i / j= 5 d> error. ans > b.---------------------------------------------------------------------------------------------------------------------------------67) What is the Output of the Program ?main(){ int a = 1; #define p a printf("%d %d ",a++,p++) ;} a) 1, 0 b) 2, 0 c) 1 2 d) none of the above (2,1) Ans (d)---------------------------------------------------------------------------------------------------------------------------------68)#include<stdio.h> main(){ #include<stdio.h> int a = 90 ; printf("%d",a) ; }a) 90 b) compilation error c) linker error d) runtime error Ans (a)--------------------------------------------------------------------------------------------------------------------------------69) What is the Output of the Program ?main(){main() ;}a) compilation error b) runtime error c) executes until the stack overflows(1) d) none of the above Ans (c)--------------------------------------------------------------------------------------------------------------------------------70) What is the Output of the Program ?#define max "hello" main(){ printf(max) ;}a. compilation error b. Preprocessing error c. runtime error d. hello Ans (d)--------------------------------------------------------------------------------------------------------------------------------71) What is the Output of the Program ?#define max main() main() { max ; printf("hello wolrd\n ") ; } a. compilation error b. Preprocessing error c. runtime error d .executes until the stack overflows ans:d---------------------------------------------------------------------------------------------------------------------------------72) What is the Output of the Program ?typedef int *p ; main() { int a = 90 ; p p1 ; p1 = &a ; printf("%d",*p1) ; }a. 90 b. compilation error c. runtime error d. none of the above Ans (a)--------------------------------------------------------------------------------------------------------------------------------73) What is the Output of the Program ?main() { int i = 1 ; printf(i ?"one" : "zero") ; } a. one b. zero c.error d. both and b Ans (a)--------------------------------------------------------------------------------------------------------------------------------74) What is the Output of the Program ?main(){ int i = 1 ;printf("%d",i ? 1 : 0) ;}a. 1 b. 0 c. error d. none of the above ans(a)--------------------------------------------------------------------------------------------------------------------------------75). What is the Output of the Program ?main() {int a = 90 , b = 100 ;a++ ;a = (a ^ b) ^ (a = b ); b = a^b^a ;--a ;printf("%d %d",a++,b++) ; }a. 90 100 b. 100 90 c. 101 91 d. 91 101 Ans (a)--------------------------------------------------------------------------------------------------------------------------------76) What is the Output of the Program ?main(){ int a = 10 , b = 100 ;swap(&a , &b) ; printf("%d %d",a,b) ;}swap(int *a , int *b){*a = *a + *b ; *b = *a - *b ;*a = *a - *b ; swap1(&a , &b) ;}swap1(int **a , int **b){**a = **a + **b ;**b = **a - **b ;**a = **a - **b ;}a. 100 10 b. 10 100 (1) c lvalue is required in fun main d. error !! Ans (b)---------------------------------------------------------------------------------------------------------------------------------77)What is the Output of the Program ?main(){ void *ptr ;int a = 10 ;ptr = &a ;printf("%d",*ptr) ;}1. error 2. 10 3. 20 4. none Ans (1)---------------------------------------------------------------------------------------------------------------------------------78) What is the Output of the Program ?main(){ void *ptr ;int a = 90 ;char *ptr1 = "hello" ;ptr = a ;ptr = ptr1 ;}a. executes w/o any error b. compilation error c. runtime error d.none Ans (a)--------------------------------------------------------------------------------------------------------------------------------- 79) What is the Output of the Program ?main(){ char *p = "helloo" ;char *p1 = "strcat" ;while((*(p++) = *(p1++)) != '\0'){;}}a. error b. address is copied c. contents are copied d . none Ans (a)

Page 5: c_test

---------------------------------------------------------------------------------------------------------------------------------80). What is the Output of the Program ?int g = 10 ;main(){int a = 10 ;printf("%d",a) ;}int g ; a. 10 b. 11 c.error d. none Ans (a)---------------------------------------------------------------------------------------------------------------------------------81). What is the Output of the Program ?main(){ int a = 1 ;int b = 0 ;a = a++ + --b * a++ ;printf("%d",a) ;}a. error b. none c. 1 d .2 Ans (d)---------------------------------------------------------------------------------------------------------------------------------82) What is the Output of the Program ?struct s{ int si;union u{float uf;char uc;};}; main(){ printf("%d",sizeof(struct s));} a. 8 b. 3 c. 6 @ d. 7---------------------------------------------------------------------------------------------------------------------------------83 What is the Output of the Program ?struct st{int a;char b;}main(){} a. struct st is return type of main@ b. main is a variable of struct st.c. Compilation error d. Run time error Ans (A)--------------------------------------------------------------------------------------------------------------------------------84) What is the Output of the Program ?typedef struct info{int i;char b;} node;main(){ struct info node1;node1.i=55; printf("%d",node1.i);}a. 55 b. Not possible to use struct info c.Compilation error d. Garbage value. Ans (A)--------------------------------------------------------------------------------------------------------------------------------85) What is the Output of the Program ?struct a{int i;int display(){ printf("hello world\n");}};main(){ strcut a vara; vara.display();} a. hello b. hello world c. Compile time error d. garbage---------------------------------------------------------------------------------------------------------------------------------86. What is the Output of the Program ?struct a{ int (*ptr)();};int display(){ printf("Global Edge\n");}main(){struct a structa;structa.ptr=display;structa.ptr();}A. Global Edge B. Address of display function C. address of structa D.Error Ans (A)---------------------------------------------------------------------------------------------------------------------------------87. What is the Output of the Program ?typedef int *ABC; typedef ABC XYZ[10]; int main() { XYZ var;}1. var is an array of integer pointers. 2. var is a pointer to an integer array.Options:a) only 1 is correct. b) only 2 is correct. c) both 1 and 2 are correct.d) typedef statements are in wrong order. Ans : b---------------------------------------------------------------------------------------------------------------------------------88. What is the Output of the Program ?union tag{ int a; char x; char y;}name;(Assume Storage is Little Endian technique)int main(){name.a=258;printf("\n x = %d y = %d ",name.x,name.y);}a) x = 1 y = 1 b) x = 2 y = 2 c) x = 1 y = 2 d) x = 2 y = 1 Ans : b---------------------------------------------------------------------------------------------------------------------------------89. Consider the Program, int main(){int a[20];int *p,*q,val;p = &a[0];q = &a[10];val = q - p;printf("p %u q %u val %d ",p,q,val);} Assume p = 1000, what is the value of q and val ? a) q = 1020 val = 20 b) q = 1020 val = 10 c) q = 1010 val = 10d) q = 1010 val = 20 ans : b---------------------------------------------------------------------------------------------------------------------------------90. Consider the Program,struct key{char *word[2]; int count;char c;}abc;int main(){printf("\nsize %d",sizeof(abc));}What is the size of abc?(a) 8 (b)7(c)6(d)5 Ans : b---------------------------------------------------------------------------------------------------------------------------------91. What is the output of the following program ?main(){ int a; fun(); printf("%d",a); a=50;} fun(){ int i; *(&i+4) = 100;}a. 50 b. Garbage value c. 100 d. Compiler error---------------------------------------------------------------------------------------------------------------------------------92. What is the output of the program ?main(){ #define x 5 int b; b = x; printf("%d",b); }a. Compiler Error b. Runtime error c. Garbage value d. 5---------------------------------------------------------------------------------------------------------------------------------93. What is the output of the following program ?main(){ int a; #define y 10 a=y; printf("%d",a); }a. 10 b. Compiler error c. Run-time error d. Garbage value---------------------------------------------------------------------------------------------------------------------------------94. What will be printed on the screen ?#define s -50 main(){int s; #ifdef s printf("Hell\n");#else printf("Heaven\n"); #endif}a. Hell b. Heaven c. Compilation error d. HellHeaven---------------------------------------------------------------------------------------------------------------------------------95. Which of 'Arrays' or 'pointers' are faster ?a. Arrays b. pointers c. Both take same time d. Can't say---------------------------------------------------------------------------------------------------------------------------------96)How many times can a comment be nested ?

Page 6: c_test

A)comment_nest_limit times B)comment_limit times C)one time D)Not even Once (R)---------------------------------------------------------------------------------------------------------------------------------97)Which one MUST be correct in the following statements ? A)All Identifiers are keywords B)All Keywords are IdentifiersC)Keywords are not Identifiers D)Some keywords are Identifiers Ans (C)---------------------------------------------------------------------------------------------------------------------------------98.Select the choice which is wrong ?A)'volatile' is a reserved wordB)'volatile' is a keywordC)'volatile' is a data type D)'volatile' is a Identifier Ans (C)---------------------------------------------------------------------------------------------------------------------------------99.Consider the following Program Ans bmain(){int i,j; i = 06; j = 09; printf ("%d %d\n",i,j);} A)6 9 B)6 11 C)06 09 D)Compilation Error ---------------------------------------------------------------------------------------------------------------------------------101)What happens when we compile this program ?# undef __FILE__ # define __FILE__ "GLOBALEDGE" main(){ printf("%s\n",__FILE__); }A)Compilation Error B)Run-Time Error C)Compiles But gives a Warning D)Compiles Normally---------------------------------------------------------------------------------------------------------------------------------102).What happens when we compile this program ?# define LINE # define NAME "GESL"main() { printf("%d "%s\n",LINE,NAME); }A)Compilation Error B)Compiles but Warns C)Syntax Error D)Compiles Normally--------------------------------------------------------------------------------------------------------------------------------103)int main(){ int i = 5;if(1){static int i;i++;printf("%d", i);} printf("%d", i);}a. error b. 5,0 c. 5,1 d. 1,5 Ans (d)--------------------------------------------------------------------------------------------------------------------------------104)int main(){ int a[4] = { 23, 67, 90}; printf(" %d", a[3]);}a. junk b. error c. 0 (ans)d. 1---------------------------------------------------------------------------------------------------------------------------------105)int main(){ int i = 1, 2; printf("%d", i); }a. 1 b. 2 c. error d. none Ans (c)---------------------------------------------------------------------------------------------------------------------------------106)int main(){ int i; for( i=0; ; i++){i = i+2;break;printf("%d", i);}}a. 0 b. 2 c. error d. none (ans) Ans (d)---------------------------------------------------------------------------------------------------------------------------------107)int main(){ int i; i = 1, 2; printf("%d", i);}a. 1 (ans) b. 2 c. error d. none---------------------------------------------------------------------------------------------------------------------------------108)#include<stdio.h>int i =20;int maxlen = i;int main(){int j = i;printf("i=%d , j=%d\n", i , j);}a) i=20 , j=20 b) i=20 , j=junk c) error d) none Ans.(c)---------------------------------------------------------------------------------------------------------------------------------109)int main(){int i =10;printf("%d", j);printf("%d",i);}int j = 20;a) j=20 , i=10 b) j=junk , i=10 c) compile time error d) runtime error Ans (c)---------------------------------------------------------------------------------------------------------------------------------(110)int i =20;int i,j=10;main(){ int j =20; printf("i=%d , j=%d\n", i, j);}a) redeclaration error b) i=20 , j=10 c) i=20 , j=20 (ans)d) none Ans (c) ---------------------------------------------------------------------------------------------------------------------------------111)int main(){ int k=2, i =10; while(k--){printf("%d\n",disp(i)); }}disp(int k){ static int i=0; return i=i+k;} a) 10, 10 b) 10, 20 (ans) c) 20, 10 d) none---------------------------------------------------------------------------------------------------------------------------------112)) header files usually contains a)only definitions b)only declarations (ans) c)both d)compiled code for functions---------------------------------------------------------------------------------------------------------------------------------113) int main() { int i =3; while(i--){ int i =10;printf("%d",i);}}a) 10, 9, 8, 7, .....1 b) 10, 10, 10, 10, ... c) 10, 10, 10 (ans) d) none ---------------------------------------------------------------------------------------------------------------------------------(114)char s[] = "hello\0 world"; printf("%s...%d",s,strlen(s)); What is the output?(a) hello...5 (b) hello\0 world...12 (c) hello...12 (d) compile time error ans : (a)---------------------------------------------------------------------------------------------------------------------------------(115)printf("%%%s","hello"); What is the output?(a) %%%s (b) %%% (c) %hello (d) hello ans : (c)---------------------------------------------------------------------------------------------------------------------------------(116). What does fgetc return (a) char (b) int (c) unsigned int (d) void ans : (b)---------------------------------------------------------------------------------------------------------------------------------(117).int i = 24; printf("%xd",i); What is the output?(a) 18 (b) 24 (c) 18d (d)compile time error ans : (a)---------------------------------------------------------------------------------------------------------------------------------(118). What is return type of freopen (a) int* (b) FILE* (c) int (d) void ans : (b) ---------------------------------------------------------------------------------------------------------------------------------(119).struct node{int i;} ; main(){ struct node n1;printf("%d",n1.i);}o/p of the program:

Page 7: c_test

a. 0 b. Garbage value c. error. 4.warning Ans: b---------------------------------------------------------------------------------------------------------------------------------(120) struct node_tag {int i;struct node_tag *pt;} ;main(){printf("%d",size(node_tag));}o/p of the program:a). 4 b). 6 c).Garbage value d).error Ans:d---------------------------------------------------------------------------------------------------------------------------------(121)typedef struct node_tag {int i=0;int j;} node;main(){node n1;printf("%d",n1.i);}o/p of the program:1. 0 2. warning 3.Garbage value 4.error Ans: d---------------------------------------------------------------------------------------------------------------------------------(122) struct {int i;}node ;main(){printf("%d",node.i);}o/p of the program:(a). 0 (b). Garbage value (c). error. (d). warning Ans: (a)---------------------------------------------------------------------------------------------------------------------------------(123).struct node_tag {int a;struct node_tag *pt;} ;main(){struct node_tag n1;n1.pt=&n1; n1.pt->a=5;printf("%d",n1.a);}o/p of the program:(a). error (b). warning (c). 5 (d).Garbage value Ans: (c)---------------------------------------------------------------------------------------------------------------------------------(124) int n;scanf("%d",n); what is the output?a)read 1 integer value b)compile time error c)runtime error d)reads 0 Ans (c)---------------------------------------------------------------------------------------------------------------------------------125)strchr(s,c) what this will do?a)return pointer to first 'c' in 's' or NULL if not present b)return pointerto last 'c' in 's' or NULL if not present c)concatenate c to s in the beginning d)concatenate c to s at the end Ans :a---------------------------------------------------------------------------------------------------------------------------------(126) When calloc() is called memory is initialised to a)Garbage b)NULL c)0 d)-1 Ans (c)---------------------------------------------------------------------------------------------------------------------------------(127) (void *) is called (a)pointer to void (b)pointer to any data type (c)generic pointer(d)None of the above Ans (c)---------------------------------------------------------------------------------------------------------------------------------(128)What the putchar() will return on error a)0 b)EOF c)NULL d)-1 Ans (b)---------------------------------------------------------------------------------------------------------------------------------129)what is the output of the following ? i=5; i=i++ * i++; printf("%d",i); a)30 b)49 c)25 d)27 Ans (d)---------------------------------------------------------------------------------------------------------------------------------(130) what is the output of the following ? i=5;printf("%d",i++ * i++);a)30 b)49 c)25 d)37 Ans (c)---------------------------------------------------------------------------------------------------------------------------------(131)#include<stdio.h>int main(void){putchar("0123456789ABCDEFGHIJKL" [16 & 17 ] );return NULL;}Choice(s) : a) Error b) No Output C) Garbage d) G---------------------------------------------------------------------------------------------------------------------------------132)#include<stdio.h>int main(){char *p = "Welcome To GESL\n";*(p+10);fprintf(stderr,"%s",p);return 'c';}Choice(s) : a) prints "GESL" to stderr.b) ErrorC) Garbage d) prints "Welcome To GESL" to screen---------------------------------------------------------------------------------------------------------------------------------(133)#include<stdio.h> int main(void){ puts("hello\0world");}Choice(s) : a) Error b) hello$^@$SC) hello d) world$%^#^---------------------------------------------------------------------------------------------------------------------------------(134)#include<stdio.h> typedef char (*PFI) () ;char main(int argc,char *argv[],char *environ[]){PFI a = main;printf("%s",a);}a)Compile Time Error b)Infinite Loop c)Prints some garbage d)Run Time error ---------------------------------------------------------------------------------------------------------------------------------135) union u{int ival;float fval;char *sval;} size of u is a) 8 bytes b) 4 bytesc) compile time errord) 12---------------------------------------------------------------------------------------------------------------------------------136)struct x{int i; int j;int k; } ;struct x *p;struct x arr[3];p =&arr[0];p++;what is p pointing toa) pointing to i of arr[0]b) pointing to j of arr[0]c) pointing to k of arr[1]d) pointing to i of arr[1]Ans (d)---------------------------------------------------------------------------------------------------------------------------------137)struct a{int b;};struct b{int b;};int main(){struct a first;struct b second;first.b =10;second = first;printf("%d",second.b);}a) 10 b) garbage c) compile error d) run time error Ans: c---------------------------------------------------------------------------------------------------------------------------------138) struct a{int x;float y; double z;struct a b;};a) no error b) compile errorc) run time errord) none of the above ans : b---------------------------------------------------------------------------------------------------------------------------------139) struct a{struct b{ int a;int b;}c;int *ptr;}d;d.ptr=&d.c.a;a) compile error b) syntax error c) Both a and c d) none of the above ans : d ---------------------------------------------------------------------------------------------------------------------------------140)#include<stdio.h>int main(void){int *intPtr ;intPtr = (char*)malloc(sizeof(10));printf("\n The starting address is %d \n ",intPtr);return 0;}a) Compilation Error b) Runtime Errorc) Will give a Warning , but run any way d) neither warning nor error ans c---------------------------------------------------------------------------------------------------------------------------------141)#include<stdio.h>int main(void){FILE *fp1,*fp2;int c;fp1 = fopen("testing","a");fp2 = fopen("testing","w");while( (c = getchar()) != '\n'){fputc(c,fp1);}return 0;} /*a) Compilation Error b) Runtime Error c) contents of file testing are appended d) contents of file testing are overwritten

Page 8: c_test

---------------------------------------------------------------------------------------------------------------------------------142.#include<stdio.h>int main(void){int intNum1,intNum2,num = 1,i; printf("\nEnter first number \n");scanf("%d",&intNum1);printf("\nEnter second number \n");scanf("%d",intNum2);for(i = 0;i<=3;i++){ num = intNum1 * intNum2 * num; }printf("\n num = %d " , num);return 0;}a) Compilation Error b) Runtime Error c) Successful execution d) Junk Value ---------------------------------------------------------------------------------------------------------------------------------143).#include<stdio.h>int main(void){char str[5];char *newstr;printf("\nEnter first string \n"); scanf("%s",&str);printf("\n The string you have entered is %s ",str);newstr = gets(str);printf("\n num = %s " , newstr);printf("\n the new string is %s ",newstr);return 0;}a) Compilation Error b) Runtime Error c) Successful execution d) Junk Value ---------------------------------------------------------------------------------------------------------------------------------144)#include<stdio.h>int main(void){FILE *fp;char *str ;char *newstr;fp = fopen("source","r");newstr = fgets(str,5,fp);printf("\n The new str is %s " ,newstr);return 0;}a) Compilation Error b) Runtime Error c) Successful execution d) Segmentation Fault ---------------------------------------------------------------------------------------------------------------------------------145).int a=1,b=0, x;x = a++ && ++b;printf("%d %d %d ",a,b,x );output ?a) 1 1 2 b) 2 1 0 c) 2 0 2 d) 2 1 1 ans: d---------------------------------------------------------------------------------------------------------------------------------146.char *fn();main(){char *s;s = fn();printf("%s\n",s );}char *fn(){ return "Hello"; }output is ?a) null b) garbage c) Hello d) Compilation Error ans:c---------------------------------------------------------------------------------------------------------------------------------147)int i;for( i=0; i<10-1; i+=2 ); i+= 2; printf("i = %d\n", i );output is ?a) 12 b) 11 c) 10 d) 13 ans: a---------------------------------------------------------------------------------------------------------------------------------148 what is the output of the following program ?main(){int i; i = f();printf("%d",i );}f(){ return 1,2,3;}a) 1 b) Compilation error c) 2 d) 3 ans:d---------------------------------------------------------------------------------------------------------------------------------149)What is the difference between ++*ip and *ip++ ?a) both increment value b) ++*ip increment value and *ip++ increment addressc) both increment addressd) ++*ip increment address and *ip++ increment value ans: b---------------------------------------------------------------------------------------------------------------------------------150.What is the output of the following program ?# include <stdio.h>intmain ( void ) {int x, y, z;x = 2, y = 4;z = x && y; printf("z = %d\n", z );}1) 1 2) 0 3) None of these 4) 8 Ans = 1---------------------------------------------------------------------------------------------------------------------------------(151)What is the output of the following program ?# include <stdio.h>int main ( void ) {int x = 48;printf("x = %s\n", x );}1) 10 2)0 3) Run Time Error 4) Compilation Error Ans = 3---------------------------------------------------------------------------------------------------------------------------------152.What is the output of the following program ?# include <stdio.h># define ONE 1 # define TWO 2 # define ONE TWO# define TWO ONE intmain ( void ) { printf("ONE = %d, TWO = %d\n", ONE, TWO );}1. ONE = 1, TWO = 2 2. TWO = 1, ONE = 2 3. Compilation Error4. None of these Ans = 3---------------------------------------------------------------------------------------------------------------------------------153 If the command line arguments for the following program are <a.out> and <GlobalEdgeSoftwareLtd>, what is the output of the program ?# include <stdio.h>int main( int iargu, char **argvar ) {printf("output = %s\n", *argvar[1] );}1. GlobalEdgeSoftwareLtd 2. G 3. Compilation Error 4. Run Time Error

Ans = 4---------------------------------------------------------------------------------------------------------------------------------154What is the output of the following ?# include <stdio.h>void fun( int, int );int main ( void ) {fun( 12, ( 13, ( 14, 15 ) ) );return 0;}void fun( int x, int y ) {printf("x = %d,y = %d\n", x, y );}1. x = 12, y = 13 2. x = 14, y = 15 3. x = 12, y = 15 4. Syntax Error( Too Many Arguments to fun() ) Ans = 3---------------------------------------------------------------------------------------------------------------------------------155)#define min((a),(b)) ((a)<(b))?(a):(b) main(){ int i=0,a[20],*ptr; ptr=a; while(min(ptr++,&a[9])<&a[8]) i=i+1; printf("i=%d\n",i);} Ans:5.---------------------------------------------------------------------------------------------------------------------------------156)main(){char a[10]={1,2,3,4,5,6};int x;for(x=0;x<4;x++){ b[x]=x+'a';}printf("%s",b);} Ans:abcd56---------------------------------------------------------------------------------------------------------------------------------157)char a =0xAA ;int b ; b = (int) a ;b = b >> 4 ;printf("%x",b); What is the output of the above program segment ? ---------------------------------------------------------------------------------------------------------------------------------158) struct s1 { struct { struct { int x; } s2 } s3 }y; How does one access x in the above given structure definition ? ---------------------------------------------------------------------------------------------------------------------------------159 )What is the size of the array declared as double * X[5] ? Ans. 5 * sizeof ( double * )

Page 9: c_test

---------------------------------------------------------------------------------------------------------------------------------160void f(int y){struct s *ptr;ptr = malloc (sizeof (struct)+99*sizeof(int));}struct s{int i;float p; }; when free (ptr) is executed, what will happen?--------------------------------------------------------------------------------------------------------------------------------- 161).enum day = { jan = 1 ,feb=4, april, may}what is the value of may?a)4 b)5 c)6 d)11e)none ---------------------------------------------------------------------------------------------------------------------------------162.main{int x,j,k;j=k=6;x=2;x=j*k;printf("%d", x); ans x=36---------------------------------------------------------------------------------------------------------------------------------163) fn f(x){ if(x<=0) return; else f(x-1)+x;} ans fn(5) ....?---------------------------------------------------------------------------------------------------------------------------------164). i=20,k=0;for(j=1;j<i;j=1+4*(i/j)){k+=j<10?4:3;}printf("%d", k); ans k=4---------------------------------------------------------------------------------------------------------------------------------165. int i =10 main(){int i =20,n;for(n=0;n<=i;){int i=10 i++;}printf("%d", i); ans i=20---------------------------------------------------------------------------------------------------------------------------------166. Y=10; if( Y++>9 && Y++!=10 && Y++>10)printf("........ Y);else printf("....  ) ans : 13---------------------------------------------------------------------------------------------------------------------------------167. f=(x>y)?x:ya) f points to max of x and yb) f points to min of x and yc)errord) ........ ans : a---------------------------------------------------------------------------------------------------------------------------------168)if x is even, then(x%2)=0x &1 !=1x! ( some stuff is there)a)only two are correctb) three are correctc), d) .... ans : all are correct---------------------------------------------------------------------------------------------------------------------------------169. which of the function operator cannot be over loaded?a) <= b)?: c)== d)* ans: b and d---------------------------------------------------------------------------------------------------------------------------------170) main(){int x=10,y=15;x=x++;y=++y;printf("%d %d\n",x,y);}---------------------------------------------------------------------------------------------------------------------------------171)int x;main(){ int x=0;{int x=10;x++;change_value(x);x++;Modify_value(); printf("First output: d \n",x);}x++;change_value(x);printf("Second Output : %d\n",x);Modify_value();printf("Third Output : %d\n",x);} Modify_value(){ return (x+=10);} change_value(){ return(x+=1);}---------------------------------------------------------------------------------------------------------------------------------172)main(){int x=20,y=35;x = y++ + x++; y = ++y + ++x;printf("%d %d\n",x,y);} 57,94---------------------------------------------------------------------------------------------------------------------------------173main(){char *p1="Name"; char *p2; p2=(char *)malloc(20);while(*p2++=*p1++); printf("%s\n",p2);} name ---------------------------------------------------------------------------------------------------------------------------------174 main(){ int x=5; printf("%d %d %d\n",x,x<<2,x>>2);}

--------------------------------------------------------------------

175#define swap1(a,b) a=a+b;b=a-b;a=a-b;main(){ int x=5,y=10; swap1(x,y); printf("%d %d\n",x,y); swap2(x,y); printf("%d %d\n",x,y);}int swap2(int a,int b){ int temp; temp=a; b=a; a=temp; return;}----------------------------------------------------------------------

176main(){ char *ptr = "Ramco Systems"; (*ptr)++; printf("%s\n",ptr); ptr++; printf("%s\n",ptr);}

Page 10: c_test

Samco systems, amco systems---------------------------------------------------------------------178#include<stdio.h>main(){ char s1[]="Ramco"; char s2[]="Systems"; s1=s2; printf("%s",s1);}

-----------------------------------------------------------------

179#include<stdio.h>main(){ char *p1; char *p2; p1=(char *) malloc(25); p2=(char *) malloc(25); strcpy(p1,"Ramco"); strcpy(p2,"Systems"); strcat(p1,p2); printf("%s",p1);}

180. For the following C program#define AND &&#define ARRANGE (a>25 AND a<50)main(){int a = 30;if (ARRANGE)printf(“within range”);elseprintf(“out of range”);}What is the output?

181. For the following C program#define AREA(x)(3.14*x*x)main(){float r1=6.25,r2=2.5,a;a=AREA(r1);printf(“\n Area of the circle is %f”, a);a=AREA(r2);printf(“\n Area of the circle is %f”, a);}What is the output?Ans. Area of the circle is 122.656250        Area of the circle is  19.625000

182 What do the following statements indicate. Explain. Int (*p)[10] Int *f() Int (*pf)() Int *p[10]

183. typedef struct{char *;

nodeptr next; } * nodeptr; what does nodeptr stand for?

184

Page 11: c_test

. int *x[](); means expl: Elments of an array can't be functions. 185. struct list{ int x; struct list *next; }*head; the struct head.x =100 above is correct / wrong

l: Before using the ptr type struct variable we have to give memory to that . And also when ever the struct variable is ptr then we access the members by "->" operator. 186.o/p=? int i; i=1; i=i+2*i++; printf(%d,i); ans: 4

187. FILE *fp1,*fp2; fp1=fopen("one","w") fp2=fopen("one","w") fputc('A',fp1) fputc('B',fp2) fclose(fp1) fclose(fp2)} a.error b. c. d.ans: no error. But It will over writes on same file. 188.#include<malloc.h> char *f() {char *s=malloc(8); strcpy(s,"goodbye")} main() { char *f(); printf("%c",*f()='A'); o/p=? 189) #define MAN(x,y) (x)>(y)?(x):(y) { int i=10;j=5;k=0; k= MAX(i++,++j) printf(%d %d %d %d,i,j,k)}

190) a=10;b=5; c=3;d=3; if(a<b)&&(c=d++) printf(%d %d %d %d a,b,c,d) else printf("%d %d %d %d a,b,c,d); : ............................................. 191. what is o/p #include<stdarg.h> show(int t,va_list ptr1) { int a,x,i; a=va_arg(ptr1,int) printf("\n %d",a) } display(char) {int x; listptr; va_star(otr,s);

Page 12: c_test

n=va_arg(ptr,int); show(x,ptr); } main() { display("hello",4,12,13,14,44); } a) 13 b) 12 c) 44 d) 14 ............................................. 192.main() { int i = 10; printf(" %d %d %d \n", ++i, i++, ++i); } 193.#include<stdio.h> main() { int *p, *c, i; i = 5; p = (int*) (malloc(sizeof(i))); printf("\n%d",*p); *p = 10; printf("\n%d %d",i,*p); c = (int*) calloc(2); printf("\n%d\n",*c); } 194.#define MAX(x,y) (x) >(y)?(x):(y) main() { int i=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); } 195.#include <stdio.h> main() { enum _tag{ left=10, right, front=100, back}; printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back); } 196.main(){ int a=10,b=20; a>=5?(b=100):(b=200); printf("%d\n",b); } 197.#define PRINT(int) printf("int = %d ",int) main() { int x,y,z; x=03;y=02;z=01; PRINT(x^x); z<<=3;PRINT(x); y>>=3;PRINT(y);

}199. supposing thaty each integer occupies 4 bytes and each charactrer 1 byte , what is the output of the following programme?

#include<stdio.h>main(){ int a[] ={ 1,2,3,4,5,6,7};char c[] = {' a','x','h','o','k'};printf("%d\t %d ", (&a[3]-&a[0]),(&c[3]-&c[0]));

Page 13: c_test

}ans : 12 3

200. what is the output of the program?

#include<stdio.h>main(){struct s1 {int i; };struct s2 {int i; };struct s1 st1;struct s2 st2;st1.i =5;st2 = st1;printf(" %d " , st2.i);}

ans: errorexpl: diff struct variables should not assigned using "=" operator.201.what is the output of the program?

#include<stdio.h>main(){int i,j;int mat[3][3] ={1,2,3,4,5,6,7,8,9};for (i=2;i>=0;i--) for ( j=2;j>=0;j--)printf("%d" , *(*(mat+j)+i));}

ans : 9 6 3 8 5 2 7 4 1

202

fun(n);}int fun( int n){int i;for(i=0;i<=n;i++)fun(n-i);printf(" well done");

} howmany times is the printf statement executed for n=10?

ans: zeroexpl: Befire reaching to printf statement it will goes to infinite loop.

203.what is the output of the program?

main(){struct emp{

char emp[];int empno;float sal;

};struct emp member = { "TIGER"};printf(" %d %f", member.empno,member.sal);

ans: error. In struct variable emp[], we have to give array size. If array size given

Page 14: c_test

ans is 0, 0.00204. output of the program?

# define infiniteloop while(1)main(){infiniteloop;printf("DONE");

}

ans: noneexpl: infiniteloop in main ends with ";" . so loop will not reach end;and the DONE also will not print.

205 output of the program?

main(){int a=2, b=3;printf(" %d ", a+++b);}

ans:5expl: here it evaluates as a++ + b.

206. output of the program?

#define prn(a) printf("%d",a)#define print(a,b,c) prn(a), prn(b), prn(c)#define max(a,b) (a<b)? b:a

main(){int x=1, y=2;print(max(x++,y),x,y);print(max(x++,y),x,y);}

ans: 3 4 2

207. which of the following is the correct declaration for the function main() ?

ans: main( int , char *[])

208. if ptr is defined as

int *ptr[][100];which of the following correctly allocates memory for ptr?

ans: ptr = (int *)(malloc(100* sizeof(int));

209 the function strcmp(str1,str2) returns

210. int *x[](); means

211.#define PRINT(int) printf("int=%d",int); main() { int x,y,z; x=03;y=-1;z=01; PRINT(x^x); z<<=3;PRINT(x); y>>=3;PRINT(y); }

Page 15: c_test

212. struct list{ int x; struct list *next; }*head; the struct head.x =100 above is correct / wrong

213. '-'=45 '/'=47 printfr(%d/n,'-','-','-','-','/','/','/'); o/p =?

214.o/p=? int i; i=1; i=i+2*i++; printf(%d,i);

215.{ ch='A'; while(ch<='F'){ switch(ch){ case'A':case'B':case'C':case'D':ch++;continue; case'E':case'F':ch++; } putchar(ch); } } a)ABCDEF b.EFG c.FG d.error

216. FILE *fp1,*fp2; fp1=fopen("one","w") fp2=fopen("one","w") fputc('A',fp1) fputc('B',fp2) fclose(fp1) fclose(fp2)}

a.error b. c. d.

217 int a=1; b=2; c=3; *pointer; pointer=&c; a=c/*pointer; b=c; printf("a=%d b=%d",a,b); a. a=1 b=3 b a=3 b=3 c 3 2 d. error

218.#include<malloc.h> char *f() { char *s=malloc(8); strcpy(s,"goodbye") } main() { char *f()_; printf("%c",*f()='A'); } o/p=?

219. int sum(n) int n; if(n<1)return n; else return(n+sum(n-1)) a 10 b 16 c 14 d 15

Page 16: c_test

220. when a function is recursively called all , automatic variables are a. stored in stack b . c. d

221) #define MAN(x,y) (x)>(y)?(x):(y) { int i=10;j=5;k=0; k= MAN(i++,++j) printf(%d %d %d %d,i,j,k) }

222) a=10;b=5; c=3;d=3; if(a<b)&&(c=d++) printf(%d %d %d %d a,b,c,d) else printf("%d %d %d %d a,b,c,d); : ............................................. 223 what is o/p #include<stdarg.h> show(int t,va_list ptr1) { int a,x,i; a=va_arg(ptr1,int) printf("\n %d",a) } display(char) {int x; listptr; va_star(otr,s); n=va_arg(ptr,int); show(x,ptr); } main() { display("hello",4,12,13,14,44); } a) 13 b) 12 c) 44 d) 14 .............................................

224. if the following program (my prog) main(int size of ,char *arg[]) { while(size of arg) printf("%s",arg[--size of arg) } is run from the command line as myprog jan feb mar apr what would be the o/p a)myprog jan,feb,mar,apr b)rev c)jan,feb,mar,apr d)error .............................................

225.what is o/p main() {int i=3; while(i--) { int i=100 i--; printf("%d..",i); } } a) infinite loop b) error c) 99..99..99..99 d) 3..22..1.. ............................................. 226)what is the o/p of the program main() {

Page 17: c_test

int rows=3,colums=4; int a[rows][colums]={1,2,3,4,5,6,7,8,9,10,11,12};

i=j=k=99; for(i=0;i<rows;i++) for(j=0;j<colums;j++) if(a[k][j]<k) k=a[i][j];

printf("%d\n",k);

227. If a = 1, b = 2, c = 3.......z = 26 what is the value of p+q+r ?(a)33(b)51(c)52(d)48Ans. B228. (x-a)(x-b)(x-c)....(x-z) = ?(a)   1(b) -1(c)   0(d) Can't be determinedAns. C

229. If a = 1, b = 2, c = 3.......z = 26 what is the value of p+q+r ?(a)33(b)51(c)52(d)48Ans. B230VOID MAIN(){INT D=5;PRINTF("%F",D);}

ANS: UNDEFINED231.VOID MAIN(){INT I;FOR(I=1;I<4,I++)SWITCH(I)CASE 1: PRINTF("%D",I);BREAK;{CASE 2:PRINTF("%D",I);BREAK;CASE 3:PRINTF("%D",I);BREAK;}SWITCH(I) CASE 4:PRINTF("%D",I);}

ANS: 1,2,3,4

232.VOID MAIN(){CHAR *S="\12345S\N";PRINTF("%D",SIZEOF(S));}

ANS: 6233VOID MAIN(){UNSIGNED I=1; /* UNSIGNED CHAR K= -1 => K=255; */SIGNED J=-1; /* CHAR K= -1 => K=65535 */

Page 18: c_test

/* UNSIGNED OR SIGNED INT K= -1 =>K=65535 */IF(I<J)PRINTF("LESS");ELSEIF(I>J)PRINTF("GREATER");ELSEIF(I==J)PRINTF("EQUAL");}

ANS: LESS234VOID MAIN(){FLOAT J;J=1000*1000;PRINTF("%F",J);}

1. 10000002. OVERFLOW3. ERROR4. NONE

ANS: 4

235.INT F()VOID MAIN(){F(1);F(1,2);F(1,2,3);}F(INT I,INT J,INT K){PRINTF("%D %D %D",I,J,K);}

WHAT ARE THE NUMBER OF SYNTAX ERRORS IN THE ABOVE?

ANS: NONE.236. VOID MAIN(){INT I=7;PRINTF("%D",I++*I++);}

ANS: 56

237. #DEFINE ONE 0#IFDEF ONE PRINTF("ONE IS DEFINED ");#IFNDEF ONEPRINTF("ONE IS NOT DEFINED ");

ANS: "ONE IS DEFINED"238.VOID MAIN(){INT COUNT=10,*TEMP,SUM=0;TEMP=&COUNT;*TEMP=20;

Page 19: c_test

TEMP=&SUM;*TEMP=COUNT;PRINTF("%D %D %D ",COUNT,*TEMP,SUM);}

ANS: 20 20 20239. MAIN(){STATIC I=3;PRINTF("%D",I--);RETURN I>0 ? MAIN():0;}

ANS: 321

240. CHAR *FOO(){CHAR RESULT[100]);STRCPY(RESULT,"ANYTHING IS GOOD");RETURN(RESULT);}VOID MAIN(){CHAR *J;J=FOO()PRINTF("%S",J);}

ANS: ANYTHING IS GOOD.241.VOID MAIN(){CHAR *S[]={ "DHARMA","HEWLETT-PACKARD","SIEMENS","IBM"};CHAR **P;P=S;PRINTF("%S",++*P);PRINTF("%S",*P++);PRINTF("%S",++*P);}

ANS: "HARMA" (P->ADD(DHARMA) && (*P)->HARMA)"HARMA" (AFTER PRINTING, P->ADD(HEWLETT-PACKARD) &&(*P)-HARMA) "EWLETT-PACKARD"

242 GIVEN THE FOLLOWING STATEMENT ENUM DAY = { JAN = 1 ,FEB=4, APRIL, MAY} WHAT IS THE VALUE OF MAY?

(A) 4 (B) 5 (C) 6 (D) 11(E) NONE OF THE ABOVE243. FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

MAIN{INT X,J,K;J=K=6;X=2;X=J*K;PRINTF("%D", X);

244. FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

FN F(X)

Page 20: c_test

{ IF(X<=0)RETURN;ELSE F(X-1)+X;}

245. FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

I=20,K=0;FOR(J=1;J<I;J=1+4*(I/J)){K+=J<10?4:3;}PRINTF("%D", K);

ANS. K=4246. FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

INT I =10MAIN(){INT I =20,N;FOR(N=0;N<=I;){INT I=10;I++;}PRINTF("%D", I);

ANS. I=20

247. FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

INT X=5;Y= X&Y

248.FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

Y=10;IF( Y++>9 && Y++!=10 && Y++>10){PRINTF("%D", Y);ELSE PRINTF("%D", Y);}

ANS. 13

249. FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

F=(X>Y)?X:Y

A) F POINTS TO MAX OF X AND YB) F POINTS TO MIN OF X AND YC)ERROR

ANS. (A)

250)WHAT IS THE SIZEOF(LONG INT)

(A) 4 BYTES (B) 2 BYTES (C) COMPILER DEPENDENT (D) 8 BYTES251. WHICH OF THE FUNCTION OPERATOR CANNOT BE OVER LOADED

(A) <=(B) ?:

Page 21: c_test

(C) ==(D) *252. FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

MAIN(){INT X=2,Y=6,Z=6;X=Y==Z;PRINTF(%D",X)} (C) BOTH E & F (D) B (E) BOTH B & C

ANS. (B)

253 main(){ int x=10,y=15; x=x++; y=++y; printf("%d %d\n",x,y);}254 int x;main(){ int x=0; { int x=10; x++; change_value(x); x++; Modify_value(); printf("First output: %d\n",x); } x++; change_value(x); printf("Second Output : %d\n",x); Modify_value(); printf("Third Output : %d\n",x);}

Modify_value(){ return (x+=10);}

change_value(){ return(x+=1);}255 main(){ int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y);}

256 main(){ char *p1="Name"; char *p2; p2=(char *)malloc(20); while(*p2++=*p1++); printf("%s\n",p2);}257 main()

Page 22: c_test

{ int x=5; printf("%d %d %d\n",x,x<<2,x>>2);}258 #define swap1(a,b) a=a+b;b=a-b;a=a-b;main(){ int x=5,y=10; swap1(x,y); printf("%d %d\n",x,y); swap2(x,y); printf("%d %d\n",x,y);}

259 int swap2(int a,int b){ int temp; temp=a; b=a; a=temp; return;}260 main(){ char *ptr = "Ramco Systems"; (*ptr)++; printf("%s\n",ptr); ptr++; printf("%s\n",ptr);}

261 #include<stdio.h>main(){ char s1[]="Ramco"; char s2[]="Systems"; s1=s2; printf("%s",s1);}

262 #include<stdio.h>main(){ char *p1; char *p2; p1=(char *) malloc(25); p2=(char *) malloc(25); strcpy(p1,"Ramco"); strcpy(p2,"Systems"); strcat(p1,p2); printf("%s",p1);}263 )main(){char a[2];*a[0]=7;*a[1]=5;printf("%d",&a[1]-a)ANS:

ans may be 1.(illegal initialization)264)#include<stdio.h>main(){char a[]="hellow";char *b="hellow";

Page 23: c_test

char c[5]="hellow";printf("%s %s %s ",a,b,c);printf(" ",sizeof(a),sizeof(b),sizeof(c));}

(ans is hellow,hellow,hellow 6,2,5 )

265)#include<stdio.h>main()

float value=10.00;printf("%g %0.2g %0.4g %f",value,value,value,value)}

(ans is 10,10,10,10.000000)

266)#include<stdio.h>void function1;int i-value=100;main(){ i-value=50;function1;printf("i-value in the function=",i-value);printf("i-value after the function=",i-value);}printf("i-value at the end of main=",i-value);functioni()i-value=25;THIS IS ROUGH IDEA OF THE PROGRAM ANS ARE1)i-value in the function=25;2)i-value after the function=50;3)i-value at the end of the main=100;

267) main(){funct(int n);{switch(n) case1: m=2; break; case2:

m=5;break;

case3:m=7;

break; default:

m=0;}

THIS IS ROUGH IDEA: (ANS:Out put is m=0)268. OUTPUT OF THE FOLLOWING PROGRAM IS

MAIN(){INT I=0;FOR(I=0;I<20;I++){SWITCH(I)CASE 0:I+=5;CASE 1:I+=2;

Page 24: c_test

CASE 5:I+=5;DEFAULT I+=4;BREAK;}PRINTF("%D,",I);}}

A) 0,5,9,13,17B) 5,9,13,17C) 12,17,22D) 16,21E) SYNTAX ERROR

ANS. (D)

269. WHAT IS THE OUPTUT IN THE FOLLOWING PROGRAM

MAIN(){CHAR C=-64;INT I=-32UNSIGNED INT U =-16;IF(C>I){PRINTF("PASS1,");IF(C<U)PRINTF("PASS2");ELSEPRINTF("FAIL2");}ELSEPRINTF("FAIL1);IF(I<U)PRINTF("PASS2");ELSEPRINTF("FAIL2")}

A) PASS1,PASS2B) PASS1,FAIL2C) FAIL1,PASS2D) FAIL1,FAIL2E) NONE OF THESE

ANS. (C)270. WHAT WILL THE FOLLOWING PROGRAM DO?

VOID MAIN(){INT I;CHAR A[]="STRING";CHAR *P="NEW SRING";CHAR *TEMP;TEMP=A;A=MALLOC(STRLEN(P) + 1);STRCPY(A,P); //LINE NUMBER:9//P = MALLOC(STRLEN(TEMP) + 1);STRCPY(P,TEMP);PRINTF("(%S, %S)",A,P);FREE(P);FREE(A);} //LINE NUMBER 15//

A) SWAP CONTENTS OF P & A AND PRINT:(NEW STRING, STRING)B) GENERATE COMPILATION ERROR IN LINE NUMBER 8C) GENERATE COMPILATION ERROR IN LINE NUMBER 5D) GENERATE COMPILATION ERROR IN LINE NUMBER 7E) GENERATE COMPILATION ERROR IN LINE NUMBER 1

Page 25: c_test

ANS. (B)271. WHAT WILL BE THE RESULT OF THE FOLLOWING PROGRAM ?

CHAR *GXXX(){STATIC CHAR XXX[1024];RETURN XXX;}

MAIN(){CHAR *G="STRING";STRCPY(GXXX(),G);G = GXXX();STRCPY(G,"OLDSTRING");PRINTF("THE STRING IS : %S",GXXX());}

A) THE STRING IS : STRINGB) THE STRING IS :OLDSTRINGC) RUN TIME ERROR/CORE DUMPD) SYNTAX ERROR DURING COMPILATIONE) NONE OF THESE

ANS. (B)

272. WHAT WILL BE RESULT OF THE FOLLOWING PROGRAM?

VOID MYALLOC(CHAR *X, INT N){X= (CHAR *)MALLOC(N*SIZEOF(CHAR));MEMSET(X,\0,N*SIZEOF(CHAR));}

MAIN(){CHAR *G="STRING";MYALLOC(G,20);STRCPY(G,"OLDSTRING");PRINTF("THE STRING IS %S",G);}

A) THE STRING IS : STRINGB) RUN TIME ERROR/CORE DUMPC) THE STRING IS : OLDSTRINGD) SYNTAX ERROR DURING COMPILATIONE) NONE OF THESE

273. WHAT WILL BE THE RESULT OF THE FOLLOWING PROGRAM?

MAIN(){CHAR P[]="STRING";INT X=0;IF(P=="STRING"){PRINTF("PASS 1");IF(P[SIZEOF(P)-2]=='G')PRINTF("PASS 2");ELSEPRINTF("FAIL 2");}ELSE{PRINTF("FAIL 1");IF(P[SIZEOF(P)-2]=='G')PRINTF("PASS 2");ELSEPRINTF("FAIL 2");}

Page 26: c_test

}

A) PASS 1, PASS 2B) FAIL 1, FAIL 2C) PASS 1, FAIL 2D) FAIL 1, PASS 2E) SYNTAX ERROR DURING COMPILATION274. WHICH OF THE CHOICES IS TRUE FOR THE MENTIONED DECLARATION ?

CONST CHAR *P;ANDCHAR * CONST P;

A) YOU CAN'T CHANGE THE CHARACTER IN BOTHB) FIRST : YOU CAN'T CHANGE THE CHARACTERR & SECOND : YOU CAN;T CHANGE THE POINTERC) YOU CAN'T CHANGE THE POINTER IN BOTH D) FIRST : YOU CAN'T CHANGE THE POINTER & SECOND : YOU CAN'T CHANAGE THE CHARACTERE) NONE

275. THE REDIRECTION OPERATORS > AND >>

A) DO THE SAME FUNCTIONB) DIFFER : > OVERWRITES, WHILE >> APPENDSC) DIFFER : > IS USED FOR INPUT WHILE >> IS USED FOR OUTPUTD) DIFFER : > WRITE TO ANY FILE WHILE >> WRITE ONLY TO STANDARD OUTPUTE) NONE OF THESE

ANS. (B)276. THE COMMAND GREP FIRST SECOND THIRD /USR/YOU/MYFILE

A) PRINTS LINES CONTAINING THE WORDS FIRST, SECOND OR THIRD FROM THE FILE /USR/YOU/MYFILEB) SEARCHES FOR LINES CONTAINING THE PATTERN FIRST IN THE FILESSECOND, THIRD, AND /USR/YOU/MYFILE AND PRINTS THEMC) SEARCHES THE FILES /USR/YOU/MYFIEL AND THIRD FOR LINES CONTAINING THE WORDS FIRST OR SECOND AND PRINTS THEMD) REPLACES THE WORD FIRST WITH THE WORD SECOND IN THE FILES THIRD AND /USR/YOU/MYFILEE) NONE OF THE ABOVE

ANS. (B)277. Find the output for the following C programint array[4][4] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};for (i=2;i<0;i--)  for (j=2;j<=0;j--)   printf(“%d”, arr[i][j]);278. Find the output for the following C program#include<stdio.h>void main(){int i,x,sum=0;int arr[6]=[1,2,3,4,5,6]for (i=0;i<4;i++)sum+ = func(arr[i]);printf(“%d”, sum);}func(int x){ int val,x;val = 2;return(x+ val++);}279. For the following C progralm  int d=0;   for(int i=0;i<31;i++)    for(int j=0;j<31;j++)     for(int k=0;k<31;k++)     if (((i+j+k) % 3)==0)    d=d+1;

Page 27: c_test

Find value of d

280. char *a[2];int const *p;int *const p;struct new { int a;int b; *var[5] (struct new)}

Describe the statements in the above given construct ?281. f()   {       int a=2;      f1(a++);   }f1(int c){printf("%d", c);}What is the value of c ?282. f1()    {       f(3);    }f(int t){switch(t);{case 2: c=3;case 3: c=4;case 4: c=5;case 5: c=6;default: c=0;}What is the value of c?283. What is the fallacy in the following program segment ?int *f1(){int a=5;return &a;}f()int *b=f1()int c=*b;}284). Give the C language equivalents of the followinga)Function returning an int pointerb)Function pointer returning an int pointerc)Function pointer returning an array of integersd)Array of function pointer returning an array of integers285. Find the fallacy in the following program segment?int a;short b;b=a;

286) Define function ? Explain arguments in functions ?

287. How does C pass variables to a function ?288. Explain the following program segment.f(){int *b;*b=2;}

289. Explain binary trees and their use ?290. Draw the diagram showing the function stack, illustrating the variables that were pushed on the stack at the point when function f2 has been introduced .

Page 28: c_test

type def struct{ double x,double y} point; }main( int argc, char *arg[3]){ double a;int b,c;f1(a,b); }f1(double x, int y){point p;stack int n;f2(p,x,y)}f2(point p, double angle){ int i,j,k,int max;}291. What is the mistake in the following program segment ?

f(){int a;void c;f2(&c,&a);}

292 a=0;    b=(a=0)?2:3;

a) What will be the value of b and why ?b) If in first statement a=0 is replaced by a = -1,  b= ?c) If in second statement a=0 is replaced by a = -1, b=?

293. char *a[2];int const *p;int *const p;struct new { int a;int b; *var[5] (struct new)}

Describe the statements in the above given construct ?294. f()   {       int a=2;      f1(a++);   }f1(int c){printf(“%d”, c);}What is the value of c ?295. f1()    {       f(3);    }f(int t){switch(t);{case 2: c=3;case 3: c=4;case 4: c=5;case 5: c=6;default: c=0;}296 What is the value of c?. Which of the following about the following twodeclaration is truei ) int *F()ii) int (*F)()

Choice :a) Both are identical

Page 29: c_test

b) The first is a correct declaration and the secondis wrongc) The first declaraion is a function returning apointer to an integer and thesecond is a pointer to function returning intd) Both are different ways of declarin pointer to afunction

Answer : c

297. What are the values printed by the followingprogram?

#define dprint(expr) printf(#expr "=%d\n",expr)

main(){int x=7;int y=3;dprintf(x/y);}

Choice:a) #2 = 2 b) expr=2 c) x/y=2 d) none

Answer: c

298. Which of the following is true of the followingprogram

main(){char *c;int *p;c =(char *)malloc(100);ip=(int *)c;free(ip);}

ans: The code functions properly releasing all thememory allocated

299.output of the following.

main(){int i;char *p;i=0X89;p=(char *)i;p++;printf("%x\n",p);}ans:0X8A

300. When an array is passed as parameter to a function,which of the followingstatement is correct

choice:a) The function can change values in the originalarrayb) In C parameters are passed by value. The funcitoncannot change the originalvalue in the array

Page 30: c_test

c) It results in compilation error when the functiontries to access theelements in the arrayd) Results in a run time error when the funtion triesto access the elements inthe array

Answer: a

301. The type of the controlling statement of a switchstatement cannot be of thetype

a) int b) char c) short d)float e) none

Answer : d302.What is the value of the statement (3^6) + (a^a)?

a) 3 b) 5 c) 6 d) a+18 e) None

Answer : b

303. What is the value assigned to the variable X if bis 7 ?X = b>8 ? b <<3 : b>4 ? b>>1:b;

a) 7 b) 28 c) 3 d) 14 e) Noneans: c

304. Which is the output produced by the followingprogrammain(){int n=2;printf("%d %d\n", ++n, n*n);}

a) 3,6 b) 3,4 c) 2,4 d) cannot determine

Answer : b

305. What is th output of the following program?int x= 0x65;main(){char x;printf("%d\n",x)}

a) compilation error b) 'A' c) 65 d) unidentified

306. What is the output of the following programmain(){int a=10;int b=6;

if(a=3)b++;printf("%d %d\n",a,b++);}

a) 10,6 b)10,7 c) 3,6 d) 3,7 e) none

Answer : d

307. What can be said of the following program?

Page 31: c_test

main(){enum Months {JAN =1,FEB,MAR,APR};Months X = JAN;if(X==1){printf("Jan is the first month");}}

a) Does not print anythingb) Prints : Jan is the first monthc) Generates compilation errord) Results in runtime error

Answer: b

308. What is the output of the following program?main(){char *src = "Hello World";char dst[100];strcpy(src,dst);printf("%s",dst);}strcpy(char *dst,char *src){while(*src) *dst++ = *src++;}

a) "Hello World" b)"Hello" c)"World" d) NULL e)unidentified

Answer: may be d

309. What is the output of the following program?

main(){int l=6;switch(l){ default : l+=2;case 4: l=4;case 5: l++;break;}printf("%d",l);}a)8 b)6 c)5 d)4 e)none

Answer : c

310. What is the output of the following program?main(){int x=20;int y=10;swap(x,y);printf("%d %d",y,x+2);}swap(int x,int y){int temp;temp =x;x=y;y=temp;}

Page 32: c_test

a)10,20 b) 20,12 c) 22,10 d)10,22 e)none

Answer:d

311. What is the output of the following problem ?#define INC(X) X++main(){int X=4;printf("%d",INC(X++));}

a)4 b)5 c)6 d)compilation error e) runtime error

Answer : d

312. what can be said of the following

struct Node {char *word;int count;struct Node left;struct Node right;}

a) Incorrect definitionb) structures cannot refer to other structurec) Structures can refer to themselves. Hence thestatement is OKd) Structures can refer to maximum of one otherstructure

Answer :c

313. What is the size of the following union.Assume that the size of int =2, size of float =4 andsize of char =1.Union Tag{int a;flaot b;char c;};

a)2 b)4 c)1 d) 7

may be b

314) What is the output of the following program? (.has been used to indicate aspace)main(){char s[]="Hello,.world";printf(%15.10s",s);}

a)Hello,.World...b)....Hello,.Worc)Hello,.Wor....d)None of the above

may be c

Page 33: c_test

315) Consider the following function written in c:

#define NULL 0

char *index(sp,c)register char *sp,c;{do {if(*sp == c)return (sp);} while (*sp++);return NULL;}

The first argument sp, is a pointer to a C string. The second argument, c, is a character. This function searches for the character c, in the string. If it is found a pointer to that location is returned else NULL is returned.This function worksa) Alwaysb) Always, but fails when the first byte contains the character cc) works when c is a non NULL character onlyd) Works only when the character c is found in the stringanswer: a

316) What is printed when this program is executedmain(){printf ("%d\n",f(7));}f(X){if (x<= 4)return x;return f(--x);}

a) 4b) 5c) 6d) 7answer: a

317) On a machine where pointers are 4 bytes long, whathappens when thefollowing code is executed.main(){int x=0,*p=0;x++; p++;printf ("%d and %d\n",x,p);}

a) 1 and 1 is printedb) 1 and 4 is printedc) 4 and 4 is printedd) causes an exception

318) Which of the following is the correct code forstrcpy, that is used to copy the contents from src to dest?

a) strcpy (char *dst,char *src){while (*src)*dst++ = *src++;}b) strcpy (char *dst,char *src)

Page 34: c_test

{while(*dst++ = *src++)}c) strcpy (char *dst,char *src){while(*src){ *dst = *src;dst++; src++;}}d) strcpy(char *dst, char *src){while(*++dst = *++src);}answer:b

319) Consider the following program

main(){int i=20,*j=&i;f1(j);*j+=10;f2(j);printf("%d and %d",i,*j);}f1(k)int *k;{*k +=15;}

f2(x)int *x;{int m=*x,*n=&m;*n += 10;}

The values printed by the program will bea) 20 and 55b) 20 and 45c) 45 and 45d) 45 and 55e) 35 and 35

320) what is printed when the following program iscompiled and executed?

intfunc (int x){if (x<=0)return(1);return func(x -1) +x;}main(){printf("%d\n",func(5));}

a) 12b) 16c) 15

Page 35: c_test

d) 11

321) Consider the following of c code in two files which will be linked together and executed .

a.c___int i;main(){i = 30;f1();printf("%d\n",i)}

b.c___static int f1(){i+=10;}

which of the following is true ?a) a.c will fail in compilation phase because f1() isnot declaredb) b.c will fail in compilation because the variable iis not declaredc) will print 30d) will print 40e) a & b

answer: e

322) Consider the following prgvoid funca (int *k){*k += 20}void funcb (int *x){int m=*x,*n = &m;*n+=10;}main(){int var = 25,*varp=&var;funca(varp);*varp += 10;funcb(varp);printf ("%d and %d\n",var,*varp);}The values printed when the above prg is complied andexecutedare:a) 20 and 55b) 20 and 45c) 45 and 55d) 55 and 55e) 35 and 35

answer: d323. Given the following statement      enum day = { jan = 1 ,feb=4, april, may}      What is the value of may? (a) 4 (b) 5 (c) 6 (d) 11

Page 36: c_test

(e) None of the above   324 Find the output for the following C program main {int x,j,k; j=k=6;x=2; x=j*k; printf("%d", x);   325. Find the output for the following C program fn f(x) { if(x<=0) return; else f(x-1)+x; }   326. Find the output for the following C program i=20,k=0; for(j=1;j<i;j=1+4*(i/j)) {k+=j<10?4:3; } printf("%d", k); Ans. k=4   327. Find the output for the following C program int i =10 main() {int i =20,n; for(n=0;n<=i;) {int i=10; i++; } printf("%d", i); Ans. i=20   328.Find the output for the following C program Y=10; if( Y++>9 && Y++!=10 && Y++>10) {printf("%d", Y); else printf("%d", Y); } Ans. 13   329. Find the output for the following C program f=(x>y)?x:y a) f points to max of x and y b) f points to min of x and y c)error Ans. (a)   330. Find the output for the following C program main() {int x=2,y=6,z=6; x=y==z; printf(%d",x) }      331. What is the output of the following program main() { int var=25,varp; varp=&var; varp p = 10; fnc(varp) printf("%d%d,var,varp); }

Page 37: c_test

(a) 20,55 (b) 35,35 (c) 25,25 (d)55,55   332) #define f(x,y) x##y void main() {

printf("%s",f("This","This is")); } a) This b)is c)ThisThis is d) None ans : c

333) #define INC(x) x++ void main() {

int a = 1;printf("%d",INC(a++));

} a) 1 b) 2 c) 3 d) Program won't compile ans : d

334) Assume the size of the int to be 4 #define NULL 0 void main() {

int i=0,*p = NULL;i++;p++;printf("%d %d",i,p);

} a) 1 4 b) 4 1 c) 4 4 d)1 1 ans : a

335) In ANSI C the output of the following C code segment is I = 5; a[5] = 5; a[6] = 11; a[7] = 12; a[I] = I++; printf("%d %d",a[5],a[6]); a) 6 11 b) 5 12 c) 5 6 d)None ans : d (answer is 5 11)

336 (3^2) + (a^a) is equal to a) 0 b) 1 c) 3 d) Data Insufficient ans:b(^ bitwise Exclusive OR)

337) void main() { int x=8;

clrscr();x = x > 10 ? x<<2 : x>7 ? x>>2 : x<<3;printf("%d",x);

} a) 1 b) 2 c) 4 d) None ans : b

338) The value of a and b after assignment areint a,b;a = (10,15);b = 10,15;

a) 10 15 b) 15 10 c)10 10 d) 15 15 ans : bb)

339)

f(int x) { if(x<=0) return 1;

return f(x-1) + x; } void main()

Page 38: c_test

{printf("%d",f(7));

} a) 28 b) 29 c) 15 d) None ans : b

340) In C arguments could be passed only a) by reference b) by value c) by name d) reference & value ans : d341) typedef struct {

char * str;NODEF next;

} * NODEF; a)works only in C b) works only in C++ c) works in C & C++ d) Won't compile in both C & C++ ans : d

342) #define NULL 0 char * f(str,c) register char * str,c; {

while(*str)if(*str++ == c) return str;return NULL;

} a) the above function will always work b) won't work for c = NULL c) won't work if c is not found d) won't work if c is the first character ans : a

343) void main() {

int x = 10, y=6,z=4;x=y==z;printf("%d",x);

} a) 0 b) 1 c)6 d) compiler Error e) None of the above ans : a

344) static functions in C could be called only a) after decleration b)after defination c) after decleration and before defination d) anywhere ans : d

345) there are 2 files called a.c and b.c a.c --- int i; void main() {

i = 10;f1();printf("%d",i);

}

b.c --- static void f1() {

i += 15; } a) a.c won't compile as f1() is not declered b) b.c won't compile as i is not declered c) prints 25 d) prints 10 ans : a

346) void f(int *x,int y) {

Page 39: c_test

int temp;temp = *x;*x = y;y = temp;

} void f1(int *x) {

int *a,b;b = *x;a = &b;*a += 10;

} void main() {

int a =10,b=5;int *c;c = &a;f(c,b);f1(c);printf("%d %d",a,b);

} a) 5 5 b)10 5 c)15 10 d)None ans : a

347) void f(int *x) {

*x += 10; } void f1(int *y) {

int temp,*pt;temp = *y;pt = &temp;*pt += 15;

} void main() {

int x = 10;f(&x);f1(&x);printf("%d",x);

} a)35 a)25 c)20 d)10 ans : c

348) expression in switch statement can not accept the data type a) int b) char c) short d) float ans : d

349) Which of the following is not a basic data type a) char b) char * c) float d) double ans : b (check it out)

350) f(int a,int b) { if(a<b) return &a;

return &b; } void main() {

int a=10,b=5,*c;c = f(b,a);printf("%d",*c);

} a) compile error b) 10 c) 5 d) Junk ans : c

351) which one could be a substitute for strcpy()

Page 40: c_test

a) while(*str++ = *dtr++); b) while(*++str)*str = *++dtr; c) while(*++str = *++dtr); d)None ans : a

352) consider the structure for double linked list struct d_list {

int a;struct d_list * next;struct d_list * prev;

};assume NULL has been assigned for first link of the list's prev pointerand the next pointer of the last link353.enum day = { jan = 1 ,feb=4, april, may}what is the value of may?a)4 b)5 c)6 d)11e)none of the above

354.main{int x,j,k;j=k=6;x=2; ans x=1x=j*k;printf("%d", x);

355. fn f(x) { if(x<=0) return; ans fn(5) ....?else f(x-1)+x;}

356. i=20,k=0;for(j=1;j<i;j=1+4*(i/j)){k+=j<10?4:3;}.main() { printf("%d",printf("HelloSoft")); } Output?

357.case 1: case 2: typedef Struct { typedef Struct { int a; char p; char b; int q; int d; char k; char e; int l; }A; }A; Assuming 'packing' is not enabled, which case will give an error of Sizeof(A) less.

358.main() { int i=3; printf("%d %d %d",i++,i,++i); }

359.main() { int i=10; int j,k=5; int a[10]; for(j=0;j<10;j++) a[j]=(i+k)+(i*k); } Optimize the above code.

Page 41: c_test

360 .main() { int *p=0x100; int *q=0x100; int k=p*q; printf("%x\n",k);} Output ?

361.Char* foo(Str...) { char str[4]; strcpy(str,"HelloSoft"); return str;} Output?

362 .int a[10][20][30][40];int *p How to access an element of a using p?

363.main() { int i=10; if(i>20) if(i==10) print("Hi"); else printf("Bye"); } Output ?

364.main() { float f; int i; //something like this i do not remember these 4 questions exactly f=(float *)malloc(sizeof((float *)*4)); } Some Question was asked i do not remenber .

365.One more Question as above asking Where will the variables be stored ?

printf("%d", k); ans k=4

366. int i =10main(){int i =20,n;for(n=0;n<=i;){int i=10 i++;}printf("%d", i); ans i=20

367. int x=5; y= x&y( MULTIPLE CHOICE QS)ans : c368. Y=10; if( Y++>9 && Y++!=10 && Y++>10)printf("........ Y);else printf("".... )ans : 13

369. f=(x>y)?x:ya) f points to max of x and y

Page 42: c_test

b) f points to min of x and yc)errord) ........

ans : a370. if x is even, then

(x%2)=0x &1 !=1x! ( some stuff is there)

a)only two are correctb) three are correctc), d) ....ans : all are correct

371. Which of the following about the following two declaration is truei ) int *F()ii) int (*F)()

Choice :a) Both are identicalb) The first is a correct declaration and the second is wrongc) The first declaraion is a function returning a pointer to an integer and thesecond is a pointer to function returning intd) Both are different ways of declarin pointer to a function

Answer : c) The first de...

372. What are the values printed by the following program?

#define dprint(expr) printf(#expr "=%d\n",expr)

main(){int x=7;int y=3;dprintf(x/y);}

Choice:a) #2 = 2 b) expr=2 c) x/y=2 d) none

Answer: c)x/y=2

373. Which of the following is true of the following program

main(){char *c;int *p;c =(char *)malloc(100);ip=(int *)c;free(ip);}ans: The code functions properly releasing all the memory allocated374.output of the following.main(){int i;char *p;i=0X89;p=(char *)i;p++;printf("%x\n",p); }ans:0X8A

Page 43: c_test

375.which of the following is not a ANSI C language keyword?

ans:Function.

376. When an array is passed as parameter to a function, which of the following statement is correct choice:a) The function can change values in the original arrayb) In C parameters are passed by value. The funciton cannot change the original value in the arrayc) It results in compilation error when the function tries to access theelements in the arrayd) Results in a run time error when the funtion tries to access the elements inthe array

Answer: a) The fu...

377. The type of the controlling expression of a switch statement cannot be of thetype

a) int b) char c) short d)float e) none

Answer : d)float

378.What is the value of the expression (3^6) + (a^a)?

a) 3 b) 5 c) 6 d) a+18 e) None

Answer : 5

379. What is the value assigned to the variable X if b is 7 ?X = b>8 ? b <<3 : b>4 ? b>>1:b;

a) 7 b) 28 c) 3 d) 14 e) Noneans: 3;

380. Which is the output produced by the following programmain(){int n=2;printf("%d %d\n", ++n, n*n);}

a) 3,6 b) 3,4 c) 2,4 d) cannot determine

Answer : b) 3,4

381. What is th output of the following program?int x= 0x65;main(){char x;printf("%d\n",x)}

a) compilation error b) 'A' c) 65 d) unidentified

282. What is the output of the following programmain(){int a=10;int b=6;

if(a=3)b++;

Page 44: c_test

printf("%d %d\n",a,b++);}

a) 10,6 b)10,7 c) 3,6 d) 3,7 e) none

Answer : d) 3,7

383. What can be said of the following program?main(){enum Months {JAN =1,FEB,MAR,APR};Months X = JAN;if(X==1){printf("Jan is the first month");}}

a) Does not print anythingb) Prints : Jan is the first monthc) Generates compilation errord) Results in runtime error

Answer: b) Prints : Jan..

384. What is the output of the following program?main(){char *src = "Hello World";char dst[100];strcpy(src,dst);printf("%s",dst);}strcpy(char *dst,char *src){ while(*src) *dst++ = *src++;}

a) "Hello World" b)"Hello" c)"World" d) NULL e) unidentified

Answer: d) NULL

385. What is the output of the following program?

main(){int l=6;switch(l){ default : l+=2;case 4: l=4;case 5: l++;break;}printf("%d",l);}a)8 b)6 c)5 d)4 e)none

Answer : c)5

386. What is the output of the following program?main(){int x=20;int y=10;swap(x,y);printf("%d %d",y,x+2);}

Page 45: c_test

swap(int x,int y){int temp;temp =x;x=y;y=temp;}

a)10,20 b) 20,12 c) 22,10 d)10,22 e)none

Answer:d)10,22

387. What is the output of the following problem ?#define INC(X) X++main(){int X=4;printf("%d",INC(X++));}

a)4 b)5 c)6 d)compilation error e) runtime error

Answer : d) compilation error388. Find the output for the following C programmain{int x,j,k;j=k=6;x=2;x=j*k;printf(“%d”, x);

389. Find the output for the following C programfn f(x) { if(x<=0)return;else f(x-1)+x;}390. What is the output of the following programmain(){ int var=25,varp;varp=&var;varp p = 10;fnc(varp)printf(“%d%d,var,varp);}20,55(b) 35,35(c) 25,25

391. int *data[10];what does the variable data denotes?

392.{ int a[]={10,20,30,40,50}; fun(a+1); }fun(int *p){ for(int i=1;i<=3;i++) printf("%d",*(p+i));}

393.enum day { saturday, sunday=3, monday, tuesday }; value of saturday,tuesday.

Page 46: c_test

394. enum day { saturday, sunday=-1, monday, tuesday }; int x=monday; value of x?

395. #define ADD(X,Y) X+Y main() { - #undef ADD(X,Y) fun(); } fun() { int y=ADD(3,2); printf("%d",y); } o/p?

396. #define ADD(X,Y) X+Y main() { #undef ADD; fun(); } fun() { #if not defined(ADD) define ADD(X+Y) X*Y int y=ADD(3,2); printf("%d",y); }

o/p?

397) main( ) { int x,y, z; x=2; y=5; z= x+++y; printf("%d %d %d", x, y z); }a)3 5 7 b)option 2 c)option 3 d)option 4Ans: a

398) # define swap(a,b) temp=a; a=b; b=temp;

main( ){ int i, j, temp;i=5;j=10;temp=0;if( i > j)swap( i, j );printf( "%d %d %d", i, j, temp);}Ans: On compiling i got ans 10, 0, 0. I did not understand the concept.

Page 47: c_test

399. Which is a good way of representing varaibles in recursion

a) local variablesb) static varaiblesc) global variables

400. Given the following c program

func() {static int i = 10;printf("%d",i);i++;}

What is the value of i if the function is called twice ?

401. Given the following c program

func(int *i, int*j){*i=*i * *i; *j=*j* *j;}

main(){ int i = 5, j = 2; func(&i,&j); printf("%d %d", i, j);}

What is the output?

402. For the following C program

int x(char *a){a=(char *) malloc(10*sizeof(char));*a="hello";}

main(){char *a="new";x(a);printf("%s",a);}

The output is

a) Hellob) Newc) Hello newd) Run time error.403

f(char *p){ p[0]? f(++p):1;printf("%c",*p);}if call that fuction with f(Aabcd) what is the output??ans:dcbaA (Just reversing the string

404 f(char *p)

Page 48: c_test

{ p=(char *)malloc(sizeof(6));strcpy(p,"HELLO");}main(){ char *p="BYE"; f(p)printf("%s",p);}what is the o/p???ans:HELLO

405To sorting array of 10 elements which sorting is besta)slectionb)bubblec)tree sortd)....ans:a

406 )size of(int)a) always 2 bytesb) depends on compiler that is being usedc) always 32 bitsd) can't tell

407)which one will over flow given two programs2prog 1: prog2:

main() main(){ {int fact; int fact=0long int x; for(i=1;i<=n;i++)fact=factoral(x); fact=fact*i;

} }

int factorial(long int x){

if(x>1) return(x*factorial(x-1);}

a) program 1;b) program 2;c) both 1 &2d) none

}

408 ) variables of fuction call are allocated ina) registers and stackb) registers and heapc) stack and heapd)

409)

main(){char str[5]="hello";if(str==NULL) printf("string null");else printf("string not null");}

Page 49: c_test

what is out put of the program?a) string is null b) string is not null c) error in program d) it executes but print nothing

410)

void f(int value){for (i=0;i<16;i++){if(value &0x8000>>1) printf("1")else printf("0");}}what is printed?a) bineray value of argument b)bcd value c) hex value d) octal value

411)void f(int *p){static val=100;val=&p;}main(){int a=10;printf("%d ",a);f(&a);printf("%d ",a);}what will be out put?a)10,10

412)

struck a{int x;float y;char c[10];}union b{int x;float y;char c[10];}which is true?a) size of(a)!=sizeof(b);b)c)d)

413)# define f(a,b) a+b#defiune g(c,d) c*d

find valueof f(4,g(5,6))a)26 b)51 c) d)

414)

find avg access time of cachea)tc*h+(1-h)*tm b)tcH+tmH

c) d) tc is time to access cache tm is time to access when miss occure

415)

main(){

Page 50: c_test

char a[10]="hello";strcpy(a,'\0');printf("%s",a);}out put of the program?a) string is null b) string is not null c) program error d)

416)

int f(int a){a=+b;

//some stuff}

main(){x=fn(a);y=&fn;what are x & y typesa) x is int y is pointer to afunction which takes integer value

417) char a[5][15];int b[5][15];address of a 0x1000 and b is 0x2000 find address of a[3][4] and b[3][4]assume char is 8 bits and int is 32 bits

a) b) c) d)418.main(){ int i,*j; i=5;j=&i;printf("\ni= %d",i); f(j);

printf("\n i= %d",i);}

void f(int*j){int k=10; j= &k;}

output isa 5 10b 10 5c 5 5d none

419 main(){ int *s = "\0";

if(strcmp(s,NULL)== 0) printf("\n s is null")p else printf("\n s is not null");}420). Find the outpur of the following C program

Page 51: c_test

void f(char *p){p=(char *) malloc(6);strcpy(p,”hello”);}void main( ){char *P=”bye”;f(p);printf(“%s’,p);}

421. For the following C programint x(char *a){a=(char *) malloc(10*sizeof(char));*a=”hello”;}main(){char *a=”new”;x(a);printf(“%s”,a);}The output isa) Hellob) Newc) Hello newd) Run time error422. From the following program           foo()           int foo(int a, int b)            {              if (a&b) return 1;              return 0;            }

    a) if either a or b are zero returns always 0    b) if both a & b are non zero returns always 1    c) if both a and b are negative returns 0   423. The  following function gives some error. What changes have to be made            void ( int a,int b)                {                    int t; t=a; a=b; b=t;                }    a) define void as int and write return t    b) change everywhere a to *a and b to *b   Q424. Which of the following is incorrect        a) if a and b are defined as int arrays then (a==b) can never be true        b) parameters are passed to functions only by values        c) defining functions in nested loops   Q425.  include<stdio.h>        void swap(int*,int*);        main()            {                int arr[8]={36,8,97,0,161,164,3,9}                for (int i=0; i<7; i++)                    {                for (int j=i+1; j<8;j++)                if(arr[i]<arr[j]) swap(&arr[i],&arr[j]);                    }            }                void swap(int*x,int*y)            {                int temp; static int cnt=0;                temp= *x;                *x=*y;

Page 52: c_test

                *y=temp;                cnt++;            }    What is cnt equal to

a) 7 b) 15 c) 1 d) none of these   Q426.      int main()                {                    FILE *fp;                    fp=fopen(“test.dat”,”w”);                    fprintf(fp,’hello\n”);                    fclose(fp);                    fp=fopen (“test.dat”,”w”);                    fprintf (fp, “world”);                    fclose(fp);                    return 0;                }

If text.dat file is already present after compiling and execution how many bytes does the file occupy ?

a) 0 bytes b) 5 bytes c) 11 bytes d) data is insufficient   Q427.    f1(int*x,intflag)            int *y;            *y=*x+3;            switch(flag)                {                    case 0:                     *x=*y+1;                    break;                    case 1:                    *x=*y;                    break;                    case 2:                     *x=*y-1;                       break;                }         return(*y)                    main()            {                *x=5;                i=f1(x,0); j=f1(x,1);                printf(“%d %d %d “,i,j,*x);            }             What is the output?

a) 8 8 8 b) 5 8 8 c) 8 5 8 d) none of these   Q428. A function is like this     swap( int a,int b)        {            int temp;            temp=a;            a=b;            b=temp;

Page 53: c_test

        }What will happen if we  put *a and *b inplace of a & b ?

429. foo() int foo(int a, int b){ if (a&b) return 1; return 0; }

a) if either a or b are zero returns always 0 b) if both a & b are non zero returns always 1 c) if both a and b are negarive....... d)

430. typedef struct nt{--------} node-type node-type *p a) p =( nodetype *)malloc( size of (node-type)) b) c) d)

431. function gives some error what changes as to be made void ( int a,int b){ int t; t=a; a=b; b=t; } a)define void as int and write return tt b)change everywhere a to *a and b to *b c) d)

432. which of the following is incorrect a) if a and b are defined as int arrays then (a==b) can never be true b) parameters are passed to functions only by values c) defining functions in nested loops d)

433. include<stdio.h>void swap(int*,int*);main(){int arr[8]={36,8,97,0,161,164,3,9}for (int i=0; i<7; i++)for (int j=i+1; j<8;j++)if(arr[i]<arr[j]) swap(&arr[i],&arr[j]);}void swap(int*x,int*y){int temp; static int cnt=0;temp= *x;*x=*y;*y=temp;cnt++;}

cnt = ?

a) 7 b) 15 c)1 d)

434. int main(){ FILE *fp; fp=fopen("test.dat","w"); fprintf(fp,'hello\n"); fclose(fp); fp=fopen ("test.dat","w"); fprintf (fp, "world"); fclose(fp); return 0;

Page 54: c_test

}

if text.dat file is already present after compiling and execution how many bytes does the file occupy

a) 0 bytes b)5 bytes c)11 bytes d)data is insufficient

435. f1(int*x,intflag) int *y; *y=*x+3; switch(flag){ case 0:......... .... ........ break; case 1: *x=*y; break; case 2: ............ ....... ....... break; } return(*y) main() { *x=5; i=f1(x,0); j=f1(x,1); printf("%.........",i,j,*x); }

what is the output? a) 8 8 8 b) 5 8 8 c) 8 5 8 d)

436. Output of the following program ismain(){int i=0;for(i=0;i<20;i++){switch(i)case 0:i+=5;case 1:i+=2;case 5:i+=5;default i+=4;break;}printf("%d,",i);}}a) 0,5,9,13,17b) 5,9,13,17c) 12,17,22d) 16,21e) Syntax errorAns. (d)

437. What is the ouptut in the following programmain(){char c=-64;int i=-32unsigned int u =-16;if(c>i){printf("pass1,");if(c<u)printf("pass2");else

Page 55: c_test

printf("Fail2");}elseprintf("Fail1);if(i<u)printf("pass2");elseprintf("Fail2")}a) Pass1,Pass2b) Pass1,Fail2c) Fail1,Pass2d) Fail1,Fail2e) None of theseAns. (c)438. What will the following program do?void main(){int i;char a[]="String";char *p="New Sring";char *Temp;Temp=a;a=malloc(strlen(p) + 1);strcpy(a,p); //Line number:9//p = malloc(strlen(Temp) + 1);strcpy(p,Temp);printf("(%s, %s)",a,p);free(p);free(a);} //Line number 15//a) Swap contents of p & a and print:(New string, string)b) Generate compilation error in line number 8c) Generate compilation error in line number 5d) Generate compilation error in line number 7e) Generate compilation error in line number 1Ans. (b)

439. In the following code segment what will be the result of the function, value of x , value of y{unsigned int x=-1;int y;y = ~0;if(x == y)printf("same");elseprintf("not same");}a) same, MAXINT, -1b) not same, MAXINT, -MAXINTc) same , MAXUNIT, -1d) same, MAXUNIT, MAXUNITe) not same, MAXINT, MAXUNITAns. (a)

440. PATH = /bin : /usr : /yourhome      The file /bin/calender has the following line in itcal 10 1997The file /yourhome/calender has the following line in itcal 5 1997If the current directory is /yourhome and calender is executeda) The calendar for May 1997 will be printed on screenb) The calendar for Oct 1997 will be printed on screenc) The calendar for the current month( whatever it is) will be printedd) Nothing will get printed on screene) An error massage will be printed

Page 56: c_test

441. What will be the result of the following program ?char *gxxx(){static char xxx[1024];return xxx;}main(){char *g="string";strcpy(gxxx(),g);g = gxxx();strcpy(g,"oldstring");printf("The string is : %s",gxxx());}a) The string is : stringb) The string is :Oldstringc) Run time error/Core dumpd) Syntax error during compilatione) None of theseAns. (b)

442. What will be result of the following program?void myalloc(char *x, int n){x= (char *)malloc(n*sizeof(char));memset(x,\0,n*sizeof(char));}main(){char *g="String";myalloc(g,20);strcpy(g,"Oldstring");printf("The string is %s",g);}a) The string is : Stringb) Run time error/Core dumpc) The string is : Oldstringd) Syntax error during compilatione) None of these

444. What will be the result of the following program?main(){char p[]="String";int x=0;if(p=="String"){printf("Pass 1");if(p[sizeof(p)-2]=='g')printf("Pass 2");elseprintf("Fail 2");}else{printf("Fail 1");if(p[sizeof(p)-2]=='g')printf("Pass 2");elseprintf("Fail 2");}}a) Pass 1, Pass 2b) Fail 1, Fail 2c) Pass 1, Fail 2d) Fail 1, Pass 2e) syntax error during compilation

445. Which of the choices is true for the mentioned declaration ?const char *p;andchar * const p;

Page 57: c_test

a) You can't change the character in bothb) First : You can't change the characterr & Second : You can;t change the pointerc) You can't change the pointer in both d) First : You can't change the pointer & Second : You can't chanage the charactere) None

446. The redirection operators > and >>a) do the same functionb) differ : > overwrites, while >> appendsc) differ : > is used for input while >> is used for outputd) differ : > write to any file while >> write only to standard outpute) None of theseAns. (b)

447. The command grep first second third /usr/you/myfilea) prints lines containing the words first, second or third from the file /usr/you/myfileb) searches for lines containing the pattern first in the filessecond, third, and /usr/you/myfile and prints themc) searches the files /usr/you/myfiel and third for lines containing the words first or second and prints themd) replaces the word first with the word second in the files third and /usr/you/myfilee) None of the aboveAns. (b)448.main()

{ char **p="Hello"; printf("%s",**p); } Ans: Garbage or nothing 449 2.main() { printf("%d%c\n"); printf("%d%c\n"); }

Ans: Garbage Value

450. main() { int x=5; printf("%d%d",x++,++x); } Ans=6 6

451. main() { int x=4; printf("%d",printf(" %d %d ",x,x) ); }

Page 58: c_test

Ans: 4 4 5

452. main() { union { int i; char p; struct { int t; char e; char o; }w; }l; printf("%d\n",sizeof(l) );} Ans: 4 453. main() { int i=0,n=6; while(n-->0); i+=n; printf("%d\n",i); } Ans: -1

454. main( ) { char a[]="Hello";

printf("%c\n",*a++); }

Ans: Error

455. a=3,b=2,c=1; What's the value of k? k= a< b < c-1; Ans: 0 456. main(){ int a=3; do { printf("%d", a); a=-1;} while(a>0); } Ans: 3 457.It is not "exact" Question; But the given Answers is: a) PASS1 PASS2 b) PASS1 FAIL1 c)FAIL1 FAIL2 d)FAIL1 PASS2

main() { char c=-32; int i=-64;unsigned u=-26;if(c>i) printf("PASS1");

Page 59: c_test

if( i < c) printf("PASS2"); else printf("FAIL1"); if(i<u)printf("PASS2"); elseprintf("FAIL2"); } Ans: PASS1 PASS2 PASS1 458. main() { int i=0; for( i=0; i<=20;i++) { switch(i) {case 0: i+=5; case 1: i+=2; case 2: i+=5; default: i+=4;break; } printf("%d",i); } Ans: 16 21 459.main(){ int i=4; switch(i) { case 1: printf("HEllo"): case default: // "case" should not come with "default"printf("****");}} Ans: Error

460 main() {int sum=0,count; for(count=1;sum+=count) printf("%d\t",sum); } Ans: Error 461. #define cond(a) a>=65 && a<=90 main() { char s='R'; if( cond(s) ) printf("UPPER CASE"); else printf("LOWER CASE"); }Ans:UPPER CASE

Page 60: c_test

461.main() { static int i=5; printf("%d\t",i--); if( i)main(); } Ans: 5 4 3 2 1 462. main() { char *a1="new",*a2="dictionary",*t; swap(a1,a2); printf("(%s%s)",a1,a2); t=a1; a1=a2;a2=t; printf("-(%s%s)",a1,a2); > } swap( char *s1,char *s2){

char *temp;s1=s2;s2=s1;temp=s1; } Ans: (newdictionary)-(dictionarynew)

463.

*p++?

Ans: increments Address

464.main() { int a[]={ 10,20,30,40,50}; char*p=(char*)a; printf("%d", * ( (int *) p+4); }Ans: 50

465. find(int x,int y) { return ((x<y)?0:(x-y)):} call find(a,find(a,b)) use to find (a) maximum of a,b (b) minimum of a,b (c) positive difference of a,b (d) sum of a,b

466. integer needs 2bytes , maximum value of an unsigned integer is (a) { 2 power 16 } -1 (b) {2 power 15}-1 (c) {2 power16} (d) {2 power 15}

467 .y is of integer type then expression 3*(y-8)/9 and (y-8)/9*3 yields same value if (a)must yields same value(b)must yields different value (c)may or may not yields same value(d) none of the above

Page 61: c_test

468. 5-2-3*5-2 will give 18 if (a)- is left associative,* has precedence over - (b) - is right associative,* has precedence over - (c) - is right associative,- has precedence over * (d)- is left associative,- has precedence over *

469. printf("%f", 9/5); prints (a) 1.8, (b) 1.0, (c) 2.0, (d) none.470. if (a=7) printf(" a is 7 "); else printf("a is not 7"); prints (a) a is 7, (b) a is not 7, (c) nothing, (d) garbage.

471. if (a>b) if(b>c) s1;else s2; s2 will be executed if (a) a<= b,(b) b>c, (c) b<=c and a<=b, (d) a>b and b<=c.

472. main() { inc(); ,inc(); , inc(); } inc() { static int x; printf("%d", ++x); } prints (a) 012, (b) 123, (c) 3 consecutive unprectiable numbers(d) 111.

473.preprocessing is done (a) either before or at begining of compilation process(b) after compilation before execution(c) after loading(d) none of the above.

474. printf("%d", sizeof("")); prints (a) error (b)0 (c) garbage (d) 1.

475.main() { int a=5,b=2; printf("%d", a+++b); }

Page 62: c_test

(a) results in syntax, (b) print 7, (c) print 8, (d) none,

476. process by which one bit patten in to another by bit wise operation is (a) masking, (b) pruning, (c) biting, (d) chopping,

477.value of automatic variable that is declared but not intialized will be (a) 0,(b) -1,(c) unpredictable,(d) none,

478. int v=3, *pv=&v; printf(" %d %d ", v,*pv); output will be (a) error (b) 3 address of v, (c) 3 3 (d) none.

479. declaration enum cities{bethlehem,jericho,nazareth=1,jerusalem}assian value 1 to (a) bethlehem (b) nazareth (c)bethlehem & nazareth (d)jericho & nazareth

480. #include<conion.h> #include<stdio.h> void main() { char buffer[82]={80}; char *result; printf( "input line of text, followed by carriage return :\n"); result = cgets(buffer); printf("text=%s\n",result); } (a) printf("length=%d",buffer[1]); (b) printf("length=%d",buffer[0]); (c) printf("length=%d",buffer[81]); (d) printf("length=%d",buffer[2]);

481. consider scanf and sscanf function , which is true

(a) no standard function called sscanf (b) sscanf(s,...) is equivalent to scanf(...) except that input charecter are taken from string s. (c) sscanf is equivalent to scanf. (d) none of above.

482. #include <stdio.h> main() { char line[80]; scanf("%[^\n]",line); printf("%s",line); } what scanf do ? (a) compilation error . illegal format string.

Page 63: c_test

(b) terminates reading input into variable line. (c) and (d) other two options.

483. for( p=head; p!=null; p= p -> next) free(p);

(a) program run smooth. (b) compilation error. (c) run time error. (d) none of above.

484. int x[3][4] ={ {1,2,3}, {4,5,6}, {7,8,9} } (a) x[2][1] = x[2][2] =x[2][3] = 0 (b) value in fourth column is zero (c) value in last row is zero (d) none of above.485. main () { printf("%u" , main()); } (a) print garbage. (b) execution error (c) printing of starting address of function main. (d) infinite loop.

486 . int a, *b = &a, **c =&b; .... .... ..... a=4; ** c= 5;

(a) doesnot change value of a (b) assign address of c to a. (c) assign value of b to a. (d) assign 5 to a.

487 . i =5; i= (++i)/(i++); printf( "%d" , i); prints , (a) 2 (b) 5 (c) 1 (d) 6

488. FOR THE FOLLOWING C PROGRAM

CHAR S;CHAR S[6]= " HELLO";PRINTF("%S ",S[6]);

OUTPUT OF THE ABOVE PROGRAM ?

(A) 0

Page 64: c_test

(B) ASCII 0(C) I(D) UNPREDICTABLE

489. FOR THE FOLLOWING C PROGRAM

UNSIGNED CHAR C;FOR ( C=0;C!=256;C++2)PRINTF("%D",C);

NO. OF TIMES THE LOOP IS EXECUTED ?

(A) 127(B) 128(C) 256(D) INFINITELY

490. For the following C program

Struct(s){int a;long b;}

Union (u){int a;long b;}

Print sizeof(s)and sizeof(u) if sizeof(int)=4 and sizeof(long)=4491. For the following C program

Switch (i)i=1;case 1i++;case 2 ++i;break; case 3--i;

Output of i after executing the program

492. For the following C program

char S;char S[6]= " HELLO";printf("%s ",S[6]);

output of the above program ?

(a) 0(b) ASCII 0(c) I(d) unpredictable

493. For the following C program

Unsigned char c;for(c=0;c!=256;c++2)printf("%d",c);

No. of times the loop is executed ?

Page 65: c_test

(a) 127(b) 128(c) 256(d) infinitely

494. For the following program

int i;i=2;i++;if(i==4){printf(i=4);}else{printf(i=3);}

Output of the program ?

a) 4 b) 3c) unpredictabled) none

Ans. (b)

495. What is FAT?.

a) File Allocation Tableb) File Access Tablec) FDD Allocation Tabled) None of the above

Ans. (a)496. Struct(s) { int a; long b; } Union (u) {int a; long b; } Print sizeof(s)and sizeof(u) if sizeof(int)=4 and sizeof(long)=4

497.Switch (i) i=1; case 1 i++; case 2 ++i; break; ( ans : 1,2,3,none) case 3 --i; Output of i after executing the program

498. char S; char S[6]= " HELLO"; printf("%s ",S[6]);

output of the above program ? (0, ASCII 0, I,unpredictable)

499. Unsigned char c; for ( c=0;c!=256;c++2) printf("%d",c);

Page 66: c_test

No. of times the loop is executed ? (127,128,256,infinitely)500 union endian{ unsigned int i; char c;};void main(){ printf("%d", sizeof(union endian) );} :2 :3 :4 :8

Q501. What will be the output of the following program:class mox{ public: mox() { cout << "constructor " ; } void foo() { cout << "foo() " ; } ~mox() { cout << "destructor " ; }};void main(){ mox *m; m=(mox *) malloc(sizeof(mox)); m->foo(); free(m);} :foo() :constructor foo() destructor :constructor destructor :No output

Q502. Which statement is not true: :You can legally & explicitely call destructors in C++ :You can define virtual destructors :You can sucessfully make polymorphic calls in a destructor :You cannot overload destructors

Q503. In the following class, the compiler will automatically add the following functions to the classclass foo{} :The default constructor & destructor :The overloaded = operator :The copy constructor :All of the above Q504. What is the output of the followng program:void foo(char *p){ p = (char *) 0xFFFF;}

Page 67: c_test

void main(){ char *p = 0x0000; foo(p); printf("%X", p);} :0x0000 :0xFFFF :0xffff :Will crash when run

Q505. What will be the output of the following program:void main(void){ int i=0; int &iref=i; int j=10; iref=j; i++; j++; iref++; cout << i << " " << iref << " " << j; }:0 12 12 :12 12 11 :13 13 13 :2 2 11

Q506. What will be the output of the following program

int i = 50;void foo(int i){ i *= 2;}void main(){ int i=1; foo(i); printf("%d", i);} :1 :2 :50 :100 Q507. Consider the function declaration and choose the correct statement void foo( int &i ) const; :The function foo is a valid declaration, and foo can not change the value of i :The function foo is a valid declaration, and foo can not change the value of the member variables of the class to which it belongs :The function foo is a valid declaration, and foo can not be overriden in the derived class :The function foo is a valid declaration and foo can not be overloaded

Q508. What will be the output of the following program

int foo(){ static int i=0; i++; return i;}void main()

Page 68: c_test

{ printf("%d ", foo()); printf("%d ", foo()); printf("%d ", foo()); } :Compilation Error :0 0 0 :1 1 1 :1 2 3

Q509. In C you can, :Define local static variables :Define global static variables :Define static functions :Define all of the above

Q510. Consider the following code snippet:class foo(){ foo() {}}void main(){ foo fArr[100];}In what sequence are the destructors called: :None : because arrays are not an Object in C++ :None : because it is a local array :fArr[0] .. fArr[1] ... fArr[99] :fArr[99] .. fArr[1] ... fArr[0]

Q511. What will be the output of the following program/* Assume sizeof char=1, int=2, float=4 Assume sizeof a pointer =4*/void main(){ char *cp; int *ip; float *fp; printf("%d %d %d", sizeof(*cp), sizeof(*ip), sizeof(*fp));} :Compilation Error :1 2 4 :2 2 2 :4 4 4

Q512. What is the output of the following program:

/* Assume sizeof char=1, int=2, float=4 Assume sizeof a pointer =4*/class base{ private: int i;}class derived : private base{ public:

Page 69: c_test

int i;}void main(){ base b; derived d; cout << sizeof(base) << " " << sizeof(b) << " " << sizeof(derived) << " " << sizeof(d);}

:2 2 2 2 :2 2 4 4 :2 4 4 4 :2 4 2 4

Q513. What is the output of the following program:/* Assume sizeof char=1, int=2, float=4 Assume sizeof a pointer =4*/struct employee{ char* name; float sal;};void main(){ struct employee e1; e1.sal = 50.0; e1.name = (char *) malloc(30); strcpy(e1.name, "Sachin 10 the great."); printf("%d %d", sizeof(employee), sizeof(e1));} :8 8 :8 30 :8 34 :8 38

Q514. Consider the following pointer _expression: --*p++; In what order are the operators executed, state them from the first executed to the last executed. :-- * ++ :* -- ++ :++ -- * :* ++ --

Q515. What is the output of the following program:struct employee{ char* name; float sal;};void main(){ struct employee e1, e2; e1.sal = 50.0; e2.sal = 150.0; e1.name = (char *) malloc(20); e2.name = (char *) malloc(20);

Page 70: c_test

e1 = e2; strcpy(e1.name, "Kapil Dev"); strcpy(e2.name, "Sunil Gavaskar"); printf("%s %f", e1.name. e1.sal);}:Kapil Dev 50.0 :Sunil Gavaskar 150.0 :Kapil Dev 150.0 :Sunil Gavaskar 50.0

Q516. What will be the output of the following program#define SQUARE(x) x * xvoid main(){ printf("%d ", SQUARE(3+2)); } :5 :10 :11 :25

Q517. How do you catch all exceptions in C++?:catch( all ) :catch(Exception) :catch( void* ) :catch(...)

Q518 delete NULL; :will crash the system :will through a Memory Exception :will do nothing :will give a compile time error

Q519. What will be the output of the following program/* Assume sizeof char=1, int=2, float=4 Assume sizeof a pointer =4*/void main(){ char *cp; int *ip; float *fp; printf("%d %d %d", sizeof(cp), sizeof(ip), sizeof(fp));} :Compilation Error :1 2 4 :2 2 2 :4 4 4

Q520. What will be the output of the following: class Base { public : virutal int Show( ) { printf( "Base" ); } ; } class Derived : public Base { public : int Show( ) { printf( "Derived" ); } ;

Page 71: c_test

} class Derived2 : public Derived { public : int Show( ) { printf( "Dervied1" ); } ; } main() { Derived2 obj2; Base *pBase = NULL; pBase = &obj2; pBase->Show(); } :Base :Dervied :Dervied1 :A Compilation error

Q521. A vtable contains : :pointers to virtual functions of a class :pointers to virtual base classes :references to virtual functions of a class :references to virtual base classes Q522. What will be the output of the following program:class foobar{ static int i; public: foobar() { i++; } void foo(void) { i++; } void show() { cout << i << " "; }};static int foobar::i;void main(){ foobar f1,f2,f3 ; f1.foo(); f2.foo(); f2.foo(); f1.show(); f3.show() getch();} :0 0 :2 1 :2 0 :6 6 Q523. What happens when you increment a void* ? :Compilation error. :It goes up by the size of a pointer. :It goes up by the size of the type it is pointing to. :Run Time error Q524. What happens when you increment a void** ? :Compilation error :It goes up by the size of a pointer :It goes up by the size of the type it is pointing to :Run Time error Q526. What will be the output of the following programvoid main()

Page 72: c_test

{ int i; printf("%d", i);} :0 :-1 :0xFFFF :Garbage

Q527. What will be the output of the following program:class base{ public: void foo() { cout << "base::foo()"; }};class derived : private base{ public: void foo() { cout << "deived::foo()"; }};void main(){ derived d = new d(); d->foo();}:base::foo() :deived::foo() :Error: Cannot access private member foo in main() :Error: Ambigous call to foo()

Q528. We cannot have a private destructor because : :The compiler cannot access the destructor when destroying the class :The operating system cannot access the destructor when destroying the class :We can have a private destructor provided it is a virtual destructor :We canot have private destructor Q529. For a class Circle, the protortype of the copy constructor is::Circle() :Circle(Circle&) :Circle(Circle*) :Circle Circle()

Q530. Consider the following code snippet and choose the correct statement class Base { int Show( ) { printf( "Base" ); } ; } class Derived : public Base { virutal int Show( ) { printf( "Derived" ); } ; } class Derived2 : public Derived { int Show( ) { printf( "Dervied1" ); } ; } main() { Derived2 obj2; Base *pBase = NULL; pBase = &obj2; pBase->Show(); }

Page 73: c_test

:Base :Dervied :Dervied1 :A Compilation error

Q531. What is the output of the following program:/* Assume sizeof char=1, int=2, float=4 Assume sizeof a pointer =4*/

class foo{ public: char *c; float f;}void main(){ foo f; cout << sizeof(foo) << " " << sizeof(f);} :Compilation Error - sizeof() cannot be applied to a class name :8 8 :4 4 :Garbage Garbage

Q532. Consider the following code:struct node{ char *firstname; char *lastname; char node* next;};void main(){ struct node *nPtr = (struct node *) malloc( sizeof(struct node) ); nPtr->firstname = (char*) malloc(10); nPtr->lastname = (char*) malloc(10); nPtr->next = NULL; // deallocating allocated memory???}What is the correct way the deallocate memory in the above program.

:free(nPtr); :free( nPtr->firstname ); free( nPtr->lastname ); nPtr=NULL; :free( nPtr->firstname ); free( nPtr->lastname ); free(nPtr); :free(nPtr); free( nPtr->firstname ); free( nPtr->lastname );

Q533. You have to write a program where that implements a doubly linklist. Each node will store a float. The node declaration will have how many entries? :2 :3 :4 :5 Q534. You have to write a program where that implements a cirlular linklist. Each node will store a char*. The node declaration will have how many entries? :2 :3 :4 :5

Page 74: c_test

Q535. What is the output of the following program:class base{ public: base() { cout << "In base()";} base(int i) { cout << "In base(int)";} }class derived : private base{ public: derived() { cout << "In derived()";} derived(int i) { cout << "In derived(int)";} }void main(){ dreived d(100);} :In base() In derived() :In base(int) In derived(int) :In derived(int) :In base() In derived(int)

Q536. Difference between Encapsulation and Data abstraction is that : :Both are same :Encapsulation means putting a wrapper over data and functions, Data abstraction means hiding unnecessary information :Encapsulation means hiding unnecessary information, Data abstraction means putting a wrapper over data and functions :Encapsulation and Data abstraction cannot be compared

Q537. What should be the prototype of a function that swaps two float pointers? :void swap(float, float); :void swap(float *, float *); :void swap(float **, float **); :void swap(float ***, float ***);

Q538. What will be the output of the following program

/* Assume sizeof char=1, int=2, float=4 Assume sizeof a pointer =4*/void main(){ char *cp = (char *) 0x0000; int *ip = (int *) 0x0000; float *fp = (float *) 0x0000; cp++; ip++; fp++; printf("%d %d %d", cp, ip, fp);}

:1 1 1 :1 2 4 :2 2 2 :4 4 4

Page 75: c_test

Q539. What is the output of the followng program:void main(){ char *p = (char*) malloc( strlen("Keep the faith") ); strcpy(p,"Keep the faith" ); printf("%s", p);} :Compilation error :Keep the faith :Keep the faith :Garbage

Q540. What will be the output of the folowing: class Base { public : virtual int Show( ) { printf( "Base" ); } ; } class Derived : public Base { public : int Show( ) { printf( "Derived" ); } ; } class Derived2 : public Derived { public : int Show( int i ) { printf( "Dervied1 %d", i ); } ; } main() { Derived2 obj2; Base *pBase = NULL; pBase = &obj2; pBase->Show(); } :Base :Dervied :Dervied1 :A Compilation error Q541. How do you catch all exceptions in C++?:catch( all ) :catch(Exception) :catch( void* ) :catch(...) Q542. Which statement is not true: :You can legally & explicitely call destructors in C++ :You can define virtual destructors :You can sucessfully make polymorphic calls in a destructor :You cannot overload destructors Q543. What will be the output of the following program:

class base{

public:void foo(){ cout << "base::foo()"; }

};

class derived : private base{

Page 76: c_test

public:void foo(){ cout << "deived::foo()"; }

};

void main(){

derived d = new d();d->foo();

}

:base::foo() :deived::foo() :Error: Cannot access private member foo in main() :Error: Ambigous call to foo() Q544. In C you can, :Define local static variables :Define global static variables :Define static functions :Define all of the above Q545. What will be the output of the following program

int foo(){

static int i=0;i++;return i;

}

void main(){

printf("%d ", foo());printf("%d ", foo());printf("%d ", foo());

}

:Compilation Error :0 0 0 :1 1 1 :1 2 3 Q546. What is the output of the followng program:

void foo(char *p){

p = (char *) 0xFFFF;}

void main(){

char *p = 0x0000;foo(p);printf("%X", p);

}

:0x0000 :0xFFFF :0xffff :Will crash when run Q547. When a class is derived from the base class with protected access specifier eg class A : protected B

Page 77: c_test

:Only the protected members of class B are accessible in class A :Only the protected and public members of class B are accessible in class A :Only the public members of class B are accessible in class A :None of the members of class B are accessible in class A Q548. What will be the output of the following program

/*Assume sizeof char=1, int=2, float=4Assume sizeof a pointer =4

*/void main(){

char *cp;int *ip;float *fp;

printf("%d %d %d", sizeof(cp), sizeof(ip), sizeof(fp));}

:Compilation Error :1 2 4 :2 2 2 :4 4 4 Question :

Q549. What is the output of the following program:

class base{

public:base(){ cout << "In base()";}base(int i){ cout << "In base(int)";}

}

class derived : private base{

public:derived(){ cout << "In derived()";}derived(int i){ cout << "In derived(int)";}

}

void main(){

dreived d(100);}

:In base() In derived() :In base(int) In derived(int) :In derived(int) :In base() In derived(int) Q550. Consider the following pointer expression:

--*p++;

In what order are the operators executed, state them from the first executed to the last executed.

:-- * ++ :* -- ++

Page 78: c_test

:++ -- * :* ++ --Q551. You have to write a program where that implements a cirlular linklist. Each node will store a char*. The node declaration will have how many entries?

:2 :3 :4 :5 Q552. A vtable contains :

:pointers to virtual functions of a class :pointers to virtual base classes :references to virtual functions of a class :references to virtual base classes Q553. What will be the output of the following program

void main(){

int i;printf("%d", i);

} :0 :-1 :0xFFFF :Garbage Q554. What is the output of the following program:

struct employee{

char* name;float sal;

};

void main(){

struct employee e1, e2;

e1.sal = 50.0;e2.sal = 150.0;e1.name = (char *) malloc(20);e2.name = (char *) malloc(20);

e1 = e2;

strcpy(e1.name, "Kapil Dev");strcpy(e2.name, "Sunil Gavaskar");

printf("%s %f", e1.name. e1.sal);}

:Kapil Dev 50.0 :Sunil Gavaskar 150.0 :Kapil Dev 150.0 :Sunil Gavaskar 50.0 Q15. In the following class, the compiler will automatically add the following functions to the class

class foo{}

Page 79: c_test

:The default constructor & destructor :The overloaded = operator :The copy constructor :All of the above Q556. What will be the output of the following program

/*Assume sizeof char=1, int=2, float=4Assume sizeof a pointer =4

*/class employee{

char *name;

public:employee() {}

virtual void foo(){ cout << "In foo()"; }

virtual ~employee() {}}

void main(){

employee e;

cout << sizeof(e);}

:0 :4 :8 :Garbage Q557. What will be the output of the following program:

/*Assume sizeof char=1, int=2, float=4Assume sizeof a pointer =4

*/

union endian{

unsigned int i;char c;

};

void main(){

printf("%d", sizeof(union endian) );}

:2 :3 :4 :8 Q558. What happens when you increment a void* ?

:Compilation error. :It goes up by the size of a pointer. :It goes up by the size of the type it is pointing to. :Run Time error Q559. What will be the output of the following program

Page 80: c_test

int i = 50;

void foo(int i){

i *= 2;}

void main(){

int i=1;foo(i);printf("%d", i);

}

:1 :2 :50 :100 Q560. We cannot have a private destructor because :

:The compiler cannot access the destructor when destroying the class :The operating system cannot access the destructor when destroying the class :We can have a private destructor provided it is a virtual destructor :We canot have private destructor Q561. What should be the prototype of a function that swaps two float pointers?

:void swap(float, float); :void swap(float *, float *); :void swap(float **, float **); :void swap(float ***, float ***); Q562. What will be the output of the following program:

void main(void){

int i=0;int &iref=i;int j=10;

iref=j;

i++; j++; iref++;cout << i << " " << iref << " " << j;

}

:0 12 12 :12 12 11 :13 13 13 :2 2 11 Q563. Consider the following code snippet:

class foo(){

foo() {}}

void main(){

foo fArr[100];}

Page 81: c_test

In what sequence are the destructors called:

:None : because arrays are not an Object in C++ :None : because it is a local array :fArr[0] .. fArr[1] ... fArr[99] :fArr[99] .. fArr[1] ... fArr[0] Q564. What is the output of the followng program:

void main(){

char *p = (char*) malloc( strlen("Keep the faith") );strcpy(p,"Keep the faith" );printf("%s", p);

}

:Compilation error :Keep the faith :Keep the faith <followed by garbage> :Garbage Q565. You have to write a program where that implements a doubly linklist. Each node will store a float. The node declaration will have how many entries?

:2 :3 :4 :5 Q566. What will be the output of the following program:

class mox{

public:mox(){

cout << "constructor " ;}

void foo(){

cout << "foo() " ;}

~mox(){

cout << "destructor " ;}

};

void main(){

mox *m;m=(mox *) malloc(sizeof(mox));m->foo();free(m);

}

:foo() :constructor foo() destructor :constructor destructor :No output Q567. What is the output of the following program:

class foo{

Page 82: c_test

int i;

public:foo() : i(10) {}

void show(){

cout << i;}

}

void main(){

foo f;f.show();

}

:Compilation error :Gabage :0 :10 Q557. What is the output of the following program:

/*Assume sizeof char=1, int=2, float=4Assume sizeof a pointer =4

*/

class foo{

public:char *c;float f;

}

void main(){

foo f;cout << sizeof(foo) << " " << sizeof(f);

} :Compilation Error - sizeof() cannot be applied to a class name :8 8 :4 4 :Garbage Garbage Q558. Consider the function declaration and choose the correct statement void foo( int &i ) const; :The function foo is a valid declaration, and foo can not change the value of i :The function foo is a valid declaration, and foo can not change the value of the member variables of the class to which it belongs :The function foo is a valid declaration, and foo can not be overriden in the derived class :The function foo is a valid declaration and foo can not be overloaded Q559. In C++ you cannot do which of the following:

:Define a class in a class :Define a function in a funciton :Define a class in a function :You can do all of the above Q560. Consider the following code snippet and choose the correct statement

Page 83: c_test

class Base {

int Show( ) { printf( "Base" ); } ; } class Derived : public Base {

virutal int Show( ) { printf( "Derived" ); } ; } class Derived2 : public Derived {

int Show( ) { printf( "Dervied1" ); } ; }

main() {

Derived2 obj2;Base *pBase = NULL;pBase = &obj2;pBase->Show();

}

:Base :Dervied :Dervied1 :A Compilation error Q561. What happens when you increment a void** ?

:Compilation error :It goes up by the size of a pointer :It goes up by the size of the type it is pointing to :Run Time error Q562. delete NULL;

:will crash the system :will through a Memory Exception :will do nothing :will give a compile time error Q563. What will be the output of the following program

/*Assume sizeof char=1, int=2, float=4Assume sizeof a pointer =4

*/void main(){

char *cp = (char *) 0x0000;int *ip = (int *) 0x0000;float *fp = (float *) 0x0000;

cp++; ip++; fp++;printf("%d %d %d", cp, ip, fp);

}

:1 1 1 :1 2 4 :2 2 2 :4 4 4 Q564. Consider the following code:

Page 84: c_test

struct node{

char *firstname;char *lastname;char node* next;

};

void main(){

struct node *nPtr = (struct node *) malloc( sizeof(struct node) );nPtr->firstname = (char*) malloc(10);nPtr->lastname = (char*) malloc(10);nPtr->next = NULL;

// deallocating allocated memory???}

What is the correct way the deallocate memory in the above program. :free(nPtr); :free( nPtr->firstname ); free( nPtr->lastname ); nPtr=NULL; :free( nPtr->firstname ); free( nPtr->lastname ); free(nPtr); :free(nPtr); free( nPtr->firstname ); free( nPtr->lastname ); Q565. What is the output of the following program:

/*Assume sizeof char=1, int=2, float=4Assume sizeof a pointer =4

*/

class base{

private:int i;

}

class derived : private base{

public:int i;

}

void main(){

base b;derived d;

cout << sizeof(base) << " " << sizeof(b) << " " << sizeof(derived) << " " << sizeof(d);}

:2 2 2 2 :2 2 4 4 :2 4 4 4 :2 4 2 4 Q37. What will be the output of the following program

#define SQUARE(x) x * x

void main(){

printf("%d ", SQUARE(3+2));}

Page 85: c_test

:5 :10 :11 :25 Q566. What will be the output of the following:

class Base {

public :virutal int Show( ) { printf( "Base" ); } ;

} class Derived : public Base {

public :int Show( ) { printf( "Derived" ); } ;

} class Derived2 : public Derived {

public :int Show( ) { printf( "Dervied1" ); } ;

}

main() {

Derived2 obj2;Base *pBase = NULL;pBase = &obj2;pBase->Show();

}

:Base :Dervied :Dervied1 :A Compilation error

Q567. For a class Circle, the protortype of the copy constructor is:

:Circle() :Circle(Circle&) :Circle(Circle*) :Circle Circle() Q568. Difference between Encapsulation and Data abstraction is that : :Both are same :Encapsulation means putting a wrapper over data and functions, Data abstraction means hiding unnecessary information :Encapsulation means hiding unnecessary information, Data abstraction means putting a wrapper over data and functions :Encapsulation and Data abstraction cannot be compared

569. A long C program is given -- try to be familiar with few of the concepts listed belowint *num={10,1,5,22,90};main(){int *p,*q;int i;

Page 86: c_test

p=num;q=num+2;i=*p++;print the value of i, and q-p, and some other operations are there.}how the values will change? 570. One pointer diff is given like this:int *(*p[10])(char *, char*)Explain the variable assignment 571 char *a[4]={"jaya","mahe","chandra","buchi"};    What is the value of sizeof(a) /sizeof(char *) 572. For the following C programvoid fn(int *a, int *b){int *t;t=a;a=b;b=t;}main(){int a=2;int b=3;fn(&a,&b);printf("%d,%d", a,b);}What is the output?

a) Error at runtimeb) Compilation errorc) 2 3d) 3 2 573. For the following C program#define scanf "%s is a string"main(){printf(scanf,scanf);}What is the output.

Ans. %s is string is string 574. For the following C program{char *p="abc";char *q="abc123";while(*p=*q)print("%c %c",*p,*q);}

a) aabbccb) aabbcc123c) abcabc123d) infinate loop  575. What is the value of the following:printf("%u",-1)

a) -1 b) 1 c) 65336  576. For the following C program#define void intint i=300;void main(void){int i=200;

Page 87: c_test

{int i=100;print the value of i;}print the value of i;}What is the output? 578. For the following C program

int x=2;x=x<<2;printf("%d ",x);Ans. 8

579. For the following C program

int a[]={0,0X4,4,9}; /*some values are given*/int i=2;printf("%d %d",a[i],i[a]);

What is the value?

580. Consider the following program:

character cName[5] = 'great'Numeric nNum1,nNum2 =0

For (nNum1 = 0;nNum1=>5;nNum1++){if(cName[nNum1] == 'a'| cName[nNum1] != 'e'| cName[nNum1] == 'i'| cName[nNum1] != 'o'| cName[nNum1] == 'u'|){nNum2 ++}}display nNum2

What does nNum2 display.

a) 2b) 1c) 5d) 3580. How can the word YES be stored in any array.

a) array[1] = 'Y'array[2] = 'E'array[3] = 'S'array[4] = '\0'b) array[0] = "Y"array[1] = "E"array[2] = "S"array[3] = "\0"c) array[1] = "Y"array[2] = "E"array[3] = "S"d) array[0] = 'Y'array[1] = 'E'array[2] = 'S'array[3] = '\0'581. What is true about the following C functions?            (A) Need not return any value.                           (B) Should always return an integer.           (C) Should always return a float.                        (D) Should always return more than one value.

Page 88: c_test

582. enum number { a=-1, b=4, c,d,e,} what is the value of e?            (A) 7                                (B) 4                               (C) 5                               (D) 3

23. Which of the following about automatic variables within a function is correct?            (A) Its type must be declared before using the variable.                   (B) They are local.           (C) They are not initialized to zero.                                                 (D) They are global.

583. Consider the following program segment                                   int n, sum=5;                                  switch(n)                                  {                                      case 2:sum=sum-2;                                      case 3:sum*=5;                                      break;                                      default:sum=0;                                  }    if n=2, what is the value of the sum?            (A) 0                           (B) 15                           (C) 3                           (D) None of these.

584. Which of the following is not an infinite loop?                                                              (A) x=0;                                                                           (B) # define TRUE 0....          do{                                                                                    While(TRUE){....}                /*x unaltered within the loop*/                              (C) for(;;)   {....}            ....}          While(x==0);                                                             (D) While(1) {....}                  

585. Output of the following program is                                  main()                                {                                    int i=0;                                    for(i=0;i<20;i++)                                    {                                        switch(i){                                                        case 0:                                                            i+=5;                                                        case 1:                                                            i+=2;                                                        case 5:                                                            i+=5;                                                        default:                                                            i+=4;                                                        break;                                                    }                                    }                              }             (A) 5,9,13,17                   (B) 12,17,22                   (C) 16,21                   (D) syntax error.

586. What does the following function print?                                 func(int i)                                {                                    if(i%2) return 0;                                    else return 1;                                }                                main()                                {                                    int i=3;                                    i=func(i);                                    i=func(i);                                    printf("%d",i);                                }             (A) 3                                (B) 1                                   (C) 0                               (D) 2

587. What will be the result of the following program?                                char*g()                                {                                    static char x[1024];

Page 89: c_test

                                    return x;                                }                                main()                                {                                    char*g1="First String";                                    strcpy(g(),g1);                                    g1=g();                                    strcpy(g1,"Second String");                                    printf("Answer is:%s", g());                                }            (A) Answer is: First String                           (B) Answer is: Second String           (C) Run time Error/Core Dump                   (D) None of these

588. Consider the following program                                 main()                                {                                    int a[5]={1,3,6,7,0};                                    int *b;                                    b=&a[2];                                }      The value of b[-1] is            (A) 1                               (B) 3                               (C) -6                               (D) none

589. Given a piece of code                                 int x[10];                                int *ab;                                ab=x;       To access the 6th element of the array which of the following is incorrect?            (A) *(x+5)                       (B) x[5]                       (C) ab[5]                       (D) *(*ab+5} .

  590Which of the following is not a storage class in C? Static Register Extern Stack 591)Which of the following 'return' statement is correct? return, return; return(1, 2, 3); return(return 4); (return 5, return 6);

592)The second argument to fopen() function is? char const char * int * FILE * 593)What is the output of the program? #include <stdio.h> void main() { char buffer[10] = {"Genesis"}; printf(" %d ", &buffer[4]- (buffer)); } 3 4 0 Illegal pointer subtraction 4

594 If "arr" is an array of 5 x 5 dimension, arr[2][4] is same as

**(a+3+4) *(a+3)+*(a+4) **(a+3)+4

Page 90: c_test

*(*(a+2)+4)

595. Output of the following program is main() { int i=0; for(i=0;i<20;i++) { switch(i){ case 0: i+=5;case 1: i+=2;case 5: i+=5;default: i+=4;break; } } } (A) 5,9,13,17 (B)12,17,22 (C) 16,21 (D) syntax error.596 What will be the result of the following program? char*g() { static char x[1024]; return x; } main() { char*g1="First String"; strcpy(g(),g1); g1=g(); strcpy(g1,"Second String"); printf("Answer is:%s", g()); } (A) Answer is: First String (B) Answer is: Second String (C) Run time Error/Core Dump (D) None of these

597)Output Of the program?.

void zap(int n) {

if(n<=1) zap =1; else zap= zap(n-3)+zap(n-5);

}

void main() {

zap(6); }

598)void main(){

char i,j;

Page 91: c_test

i=255,j=255;cout<<i<<j;}

599)#define STYLE char

void main(){

typedef STYLE char { ------------- some statements; -------------- };}

600)

class base{

int top; base() { top=1; }

}

class derived : public base(){

derived : base() <--- Note this. {

top=2; cout<<top; cout<<base()::top; cout<<::top; }

}

void main() {

derived d; }

601)

void main() {

int n; ------------- Some Complex statements on n; --------------

Page 92: c_test

cout<<precision(n); }

602)

void main() {

int i; if ( odd(i) ) { cout<<i; }}

603)State True or false

A Pure virtual Function has no body.

604)

If the derived class has no constructor, the complier will take the base class constructor.

605)

If no copy constructor is provided the compiler will itself provide the copy constructor.

606)

# ifdef TRUE int I=0;#endif

void main(){

int j,k;

j=5;k=4;

cout<<I<<j<<k;}

607)

void val() {

------------------ Some Statements; ------------- }

void main() { enum grade{GRAD,BAD,GOOD}; BAD.val();

Page 93: c_test

}

608.main(){

char *p1="Name";char *p2;p2=(char *)malloc(20);while(*p2++=*p1++);printf("%s\n",p2);

}

Ans : An empty String

609.

main(){ int x=20,y=35;

x = y++ + x++;y = ++y + ++x;printf("%d %d\n",x,y);

}

Ans 57 94

610.

main(){ int x=5;

printf("%d %d %d\n",x,x<<2,x>>2);}

Ans 5 20 1

611#define swap1(a,b) a=a+b;b=a-b;a=a-b;main(){

int x=5,y=10;swap1(x,y);printf("%d %d\n",x,y);swap2(x,y);printf("%d %d\n",x,y);

}

int swap2(int a,int b){

int temp;temp=a;b=a;a=temp;return;

}

Ans 10 5 10 5

Page 94: c_test

611).main(){ char *ptr = "Ramco Systems"; (*ptr)++;

printf("%s\n",ptr);ptr++;printf("%s\n",ptr);

} Ans Samco Systems

amco Systems

612).

#include<stdio.h>main(){

char s1[]="Ramco";char s2[]="Systems";s1=s2;printf("%s",s1);

}

Ans Compilation error giving it cannot be an modifible 'lvalue'

613).

#include<stdio.h>main(){

char *p1;char *p2;p1=(char *) malloc(25);p2=(char *) malloc(25);strcpy(p1,"Ramco");strcpy(p2,"Systems");strcat(p1,p2);printf("%s",p1);

}

Ans : RamcoSystems

614. Another Problem with

# define TRUE 0

some code

while(TRUE){

some code

}

This won't go into the loop as TRUE is defined as 0Ans NONE OF THE ABOVE i.e D

Page 95: c_test

615 int x;main(){

int x=0;{

int x=10;x++;change_value(x);x++;Modify_value();printf("First output: %d\n",x);

}x++;change_value(x);printf("Second Output : %d\n",x);Modify_value();printf("Third Output : %d\n",x);

}

Modify_value(){

return (x+=10);}

change_value(){

return(x+=1);}

Ans : 12 1 1

116).main(){

int x=10,y=15;x=x++;y=++y;printf("%d %d\n",x,y);

}

Ans : 11 16

618).

main(){

int a=0;if(a=0) printf("Ramco Systems\n");printf("Ramco Systems\n");

}

Page 96: c_test

Ans : Ony one time "Ramco Systems"

will be printed

I

619 #INCLUDE<STDIO.H>INT SUMELEMENT(INT *,INT);VOID MAIN(VOID){INT X[10];INT I=10;FOR(;I;){I--;*(X+I)=I;}PRINTF("%D",SUMELEMENT(X,10));}INT SUMELEMENT(INT ARRAY[],INT SIZE){INT I=0;FLOAT SUM=0;FOR(;I<SIZE;I++)SUM+=ARRAY[I];RETURN SUM;}

Q620) FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

#INCLUDE<STDIO.H>VOID MAIN(VOID);INT PRINTF(CONST CHAR*,...);VOID MAIN(VOID){INT I=100,J=10,K=20;-- INT SUM;FLOAT AVE;CHAR MYFORMAT[]="AVE=%.2F";SUM=I+J+K;AVE=SUM/3.0;PRINTF(MYFORMAT,AVE);}

Q621) FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

#INCLUDE<STDIO.H>VOID MAIN(VOID);{INT A[10];PRINTF("%D",((A+9) + (A+1)));}

Q622) FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

#INCLUDE<STDIO.H>VOID MAIN(VOID){STRUCT S{INT X;FLOAT Y;}S1={25,45.00};UNION U{INT X;

Page 97: c_test

FLOAT Y;} U1;U1=(UNION U)S1;PRINTF("%D AND %F",U1.X,U1.Y);}

Q623) FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

#INCLUDE<STDIO.H>VOID MAIN(VOID){UNSIGNED INT C;UNSIGNED X=0X3;SCANF("%U",&C);SWITCH(C&X){CASE 3: PRINTF("HELLO!\T");CASE 2: PRINTF("WELCOME\T");CASE 1: PRINTF("TO ALL\T");DEFAULT:PRINTF("\N");}}

Q624) FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

#INCLUDE<STDIO.H>INT FN(VOID);VOID PRINT(INT,INT(*)());INT I=10;VOID MAIN(VOID){INT I=20;PRINT(I,FN);}VOID PRINT(INT I,INT (*FN1)()){PRINTF("%D\N",(*FN1)());}INT FN(VOID){RETURN(I-=5);}

Q625) FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

#INCLUDE<STDIO.H>VOID MAIN(VOID);{CHAR NUMBERS[5][6]={"ZERO","ONE","TWO","THREE","FOUR"};PRINTF("%S IS %C",&NUMBERS[4][0],NUMBERS[0][0]);}

Q626) FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

INT BAGS[5]={20,5,20,3,20};VOID MAIN(VOID){INT POS=5,*NEXT();*NEXT()=POS;PRINTF("%D %D %D",POS,*NEXT(),BAGS[0]);}INT *NEXT(){

Page 98: c_test

INT I;FOR(I=0;I<5;I++)IF (BAGS[I]==20)RETURN(BAGS+I);PRINTF("ERROR!");EXIT(0);}

Q627) FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

#INCLUDE<STDIO.H>VOID MAIN(VOID){INT Y,Z;INT X=Y=Z=10;INT F=X;FLOAT ANS=0.0;F *=X*Y;ANS=X/3.0+Y/3;PRINTF("%D %.2F",F,ANS);}

Q628) FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

#INCLUDE<STDIO.H>VOID MAIN(VOID);{DOUBLE DBL=20.4530,D=4.5710,DBLVAR3;DOUBLE DBLN(VOID);DBLVAR3=DBLN();PRINTF("%.2F\T%.2F\T%.2F\N",DBL,D,DBLVAR3);}DOUBLE DBLN(VOID){DOUBLE DBLVAR3;DBL=DBLVAR3=4.5;RETURN(DBL+D+DBLVAR3);}

Q629) FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

#INCLUDE<STDIO.H>STATIC INT I=5;VOID MAIN(VOID){INT SUM=0;DO{SUM+=(1/I);}WHILE(0<I--);}

Q630) FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

#INCLUDE<STDIO.H>VOID MAIN(VOID){INT OLDVAR=25,NEWVAR=-25;INT SWAP(INT,INT);SWAP(OLDVAR,NEWVAR);PRINTF("NUMBERS ARE %D\T%D",NEWVAR,OLDVAR);}INT SWAP(INT OLDVAL,INT NEWVAL)

Page 99: c_test

{INT TEMPVAL=OLDVAL;OLDVAL=NEWVAL;NEWVAL=TEMPVAL;}

Q631) FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

#INCLUDE<STDIO.H>VOID MAIN(VOID);{INT I=100,J=20;I++=J;I*=J;PRINTF("%D\T%D\N",I,J);}

Q632) FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

#INCLUDE<STDIO.H>VOID MAIN(VOID);INT NEWVAL(INT);VOID MAIN(VOID){INT IA[]={12,24,45,0};INT I;INT SUM=0;FOR(I=0;IA[I];I++){SUM+=NEWVAL(IA[I]);}PRINTF("SUM= %D",SUM);}INT NEWVAL(INT X){STATIC INT DIV=1;RETURN(X/DIV++);}

Q633) FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

#INCLUDE<STDIO.H>VOID MAIN(VOID);{INT VAR1,VAR2,VAR3,MINMAX;VAR1=5;VAR2=5;VAR3=6;MINMAX=(VAR1>VAR2)?(VAR1>VAR3)?VAR1:VAR3:(VAR2>VAR3)?VAR2:VAR3;PRINTF("%D\N",MINMAX);

Q634) FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

#INCLUDE<STDIO.H>VOID MAIN(VOID);{VOID PA(INT *A,INT N);INT ARR[5]={5,4,3,2,1};PA(ARR,5);}VOID PA(INT *A,INT N){

Page 100: c_test

INT I;FOR(I=0;I<N;I++)PRINTF("%D\N",*(A++)+I);}

Q635) FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

#INCLUDE<STDIO.H>VOID MAIN(VOID);VOID PRINT(VOID);{PRINT();}VOID F1(VOID){PRINTF("\NF1():");}

Q636) FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

#INCLUDE "6.C"VOID PRINT(VOID){EXTERN VOID F1(VOID);F1();}STATIC VOID F1(VOID){PRINTF("\N STATIC F1().");}

Q637) FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

#INCLUDE<STDIO.H>VOID MAIN(VOID);STATIC INT I=50;INT PRINT(INT I);VOID MAIN(VOID){STATIC INT I=100;WHILE(PRINT(I)){PRINTF("%D\N",I);I--;}}INT PRINT(INT X){STATIC INT I=2;RETURN(I--);}

Q638) FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

#INCLUDE<STDIO.H>VOID MAIN(VOID);TYPEDEF STRUCT NTYPE{INT I;CHAR C;LONG X;} NEWTYPE;VOID MAIN(VOID)

Page 101: c_test

{NEWTYPE *C;C=(NEWTYPE *)MALLOC(SIZEOF(NEWTYPE));C->I=100;C->C='C';(*C).X=100L;PRINTF("(%D,%C,%4LD)",C->I,C->C,C->X);}

Q639) FIND THE OUTPUT FOR THE FOLLOWING C PROGRAM

#INCLUDE<STDIO.H>VOID MAIN(VOID);CONST INT K=100;VOID MAIN(VOID){INT A[100];INT SUM=0;FOR(K=0;K<100;K++)*(A+K)=K;SUM+=A[--K];PRINTF("%D",SUM);}

640 What is the parameter passing mechanism to Macros Called?

641) void func(int x,int y) { x=3; y=2; } main() { int i; func(i,i); print(i); } If the output must be 2 what is the parameter passing mechanism called? 642) which of the following code will swap the two numbers? -3 choices was given

643) which of the following is illegal for the program? main() { char const *p='p'; } 1)p++ 2) *p++ 3)(*p)++ 4) all

644) what is the output of the following program void print(int ** arr) { print("0 %f, 1 %f, 2 %f ",arr[0][0],arr[0][1],arr[0][2]); } main() { int a[][]={ {1,2,3}, {4,5,6} } int ** arr=a; print(arr); arr++; print(arr); }

Page 102: c_test

645) which of the following code swapps the two,numbers.- 4 choices were given

646 ) if the string " this is a " is present in the code of a function such as 'void func(void)' where will the variable stored in the memory. a) in the stack b) heap c) code or text segment as per implementation d) created when func is called, stored in function stack space and destroyed as it goes out .

647. If FILE1 and FILE2 are defined what files will be included in the Program.

#ifdef FILE1#include file1.h#elseifdef FILE2#include file2.1#elseifdef FILE3#include file3.h#endif

there were 4 answers ...The answer is "file1.h only".

648 int a[]={1,2,3,4}; main() { printf("%d",sizeof(a)); } What will be the output of the program when executed. Ans : 8. if integer takes 2 byte.

649 char name="Krishna Prasad"; main() { name[7] = '\0'; printf("%s",name); } what's the o/p. Ans : Compilation error. Since you can't assign a String Constant to Char variable.

650. what is the meaning of if (x^y = ~0)

651. how can you simplify this routine int max (int a, int b) { if (a > b) then return a; else return b; }

652) Which of these is an invalid dataname? a) wd-count b) wd_count c) w4count d) wdcountabcd

653) What is the output of the following program main () { unsigned int i;

for (i = 10; i >= 0; i--) printf ("%d", i);

} a) prints numbers 10 - 0 b) prints nos 10 - 1

Page 103: c_test

c) d) goes into infinite loop

654) What is the value of the following expression? i = 1; i << 1 % 2 a) 2 b) c) 1 d) 0

655) What is the value of the following expression? i = 1; i = (i <<= 1 % 2) a) 2 b) c) 0 d) erroneous syntax

What is the result?656) *A + 1 - *A + 3 a) - b) -2 c) 4 d) none of the above

657) &A[5] - &A[1]? a) b) c) 4 d)

658) C allows a) only call by value b) only call by reference c) both d) only call by value and sometimes call by reference

659) The following statement is " The size of a struct is always equal to the sum

of the sizes of its members" a) valid b) invalid c) can't say

670) How many x's are printed? for (i = 0, j = 10; i < j; i++, j--) printf ("x"); a) 10 b) 5 c) 4 d) none

671) output? main () { int i = 2, j = 3, k = 1; swap (i, j) printf ("%d %d", i, j); } swap (int i, int j) { int temp; temp = i; i = j; j = temp; } YOU KNOW THE ANSWER

672) main () { int i = 2; twice (2); printf ("%d", i); } twice (int i) { bullshit }

int i, b[] = {1, 2, 3, 4, 5}, *p; p = b; ++*p; p += 2;

673) What is the value of *p;

Page 104: c_test

a) 2 b) 3 c) 4 d) 5

674) What is the value of (p - (&p - 2))? a) b) 2 c) d)

675) x = fopen (b, c) what is b? a) pointer to a character array which contains the filename b) filename whithin double quotes c) can be anyone of the above d) none

676) x = malloc (y). Which of the following statements is correct. a) x is the size of the memory allocated b) y points to the memory allocatedt c) x points to the memory allocated d) none of the above

677) which is the valid declaration? a) #typedef struct { int i;}in; b) typedef struct in {int i;}; c) #typedef struct int {int i;}; d) typedef struct {int i;} in;

678) union { int no; char ch; } u; What is the output? u.ch = '2'; u.no = 0; printf ("%d", u.ch); a) 2 b) 0 c) null character d) none

679) Which of these are valid declarations? i) union { ii) union u_tag {

int i; int i; int j; int j;

}; };

iii) union { iv) union { int i; int i; int j; int j; FILE k; }u;

};

a) all correct b) i, ii, iv c) ii & iv d)

680) p and q are pointers to the same type of dataitems. Which of these are valid? i) *(p+q) ii) *(p-q) iii) *p - *q

a) all b) c) iii is valid sometimes

681) which are valid? i) pointers can be added ii) pointers can be subtracted iii) integers can be added to pointers a) all correct b) only i and ii

682) int *i;

Page 105: c_test

float *f; char *c; which are the valid castings? i) (int *) &c ii) (float *) &c iii) (char *) &i

683) int i = 20; printf ("%x", i); what is the output? a) x14b) 14 c) 20 d) none of the above

684) main () { char *name = "name"; change (name); printf ("%s", name); } change (char *name) { char *nm = "newname"; name = nm; } what is the output? a) name b) newname c) name = nm not valid d) function call invalid

685) char name[] = {'n', 'a', 'm', 'e'} printf ("name = \n%s", name); a) name = name b) name = followed by funk characters c) name = \nname d) none

686) int a = 0, b = 2;if (a = 0)

b = 0;else

b *= 10; what is the value of b? a) 0 b) 20 c) 2 d) none

687) int x = 2, y = 2, z = 1; what is the value of x afterh the following statmements? if (x = y%2) z = crap else crap

a) 0 b) 2 c)1 d)none

688) output? initially n = -24; printd (int n) { if (n < 0) {

printf ("-"); n = -n;

} if (n % 10)

printf ("%d", n); else

printf ("%d", n/10);

Page 106: c_test

printf ("%d", n); } a. -24 b.24 c. d.-224

689) float x, y, z; scanf ("%f %f", &x, &y);

if input stream contains "4.2 3 2.3 ..." what will x and y contain after scanf? a. 4.2, 3.0 b. 4.2, 2.3 c. d.

690) #define max(a,b) (a>b?b:a) #define squre(x) x*x

int i = 2, j = 3, k = 1; printf ("%d %d", max(i,j), squre(k));

output? a.32 b.23 c.31 d.13

691) struct adr { char *name; char *city; int zip; }; struct adr *adradr; which are valid references?

i) adr->name X ii) adradr->name iii) adr.zip X iv) adradr.zip

692) main (x, y) int x, char *y[]; { printf ("%d %s", x, y[1]); } output when invoked as prog arg1 a. 1 prog b. 1 arg1 c. 2 prog d. 2 arg1

693) extern int s; int t; static int u; main () { } which of s, t and u are availeble to a function present in another file a. only s b. s & t c. s, t, u d. none

694) main () { } int a; f1(){} f2(){}

which of the functions is int a available for?

Page 107: c_test

a. all of them b. only f2 c. only f1 d. f1 and f2 only

695

int a = 'a', d = 'd'; char b = "b", c = "cr";

main () { mixup (a, b, &c); } mixup (int p1, char *p2, char **p3) { int *temp; ....doesnt matter..... }

696) what is the value of a after mixup? a. a b.b c.c d.none of the above

697) what is the value of b after mixup? a. a b.b c.c d.none of the above

698) main () { char s[] = "T.C.S", *A; print(s); } print (char *p) { while (*p != '\0') {

if (*p != ".") printf ("%s", *p); p++;

} } output? a.T.C.S b.TCS c. d. none of the above

699) main () { int ones, twos, threes, others; int c;

ones = twos = threes = others = 0;

while ((c = getchar ()) != EOF) {

switch (c) { case '1': ++ones; case '2': ++twos; case '3': ++threes;

break; default: ++others;

break; }

} printf ("%d %d", ones, others);

Page 108: c_test

}

if the input is "1a1b1c" what is the output? a. 13 b. c. 33 d. 31

700. int f(int *a) { int b=5; a=&b; }

main() { int i; printf("\n %d",i); f(&i); printf("\n %d",i); }

what's the output .

1.10,5 2,10,10 c.5,5 d. none

701. main() { int i; fork(); fork(); fork(); printf("----"); }

how many times the printf will be executed . a.3 b. 6 c.5 d. 8

702 void f(int i) { int j; for (j=0;j<16;j++) { if (i & (0x8000>>j)) printf("1"); else printf("0"); } } what's the purpose of the program

a. its output is hex representation of i b. bcd c. binary d. decimal

703 .#define f(a,b) a+b #define g(a,b) a*b

main()

Page 109: c_test

{

int m; m=2*f(3,g(4,5)); printf("\n m is %d",m); }

what's the value of m a.70 b.50 c.26 d. 69

704. main() { char a[10]; strcpy(a,"\0"); if (a==NULL) printf("\a is null"); else printf("\n a is not null");}

what happens with it . a. compile time error. b. run-time error. c. a is null d. a is not null.

705. char a[5]="hello"

a. in array we can't do the operation . b. size of a is too large c. size of a is too small d. nothing wrong with it .

706. local variables can be store by compiler a. in register or heap b. in register or stack c .in stack or heap . d. global memory.

707 . global variable conflicts due to multiple file occurance is resolved during a. compile-time b. run-time c. link-time d. load-time

708. two program is given of factorial. one with recursion and one without recursion . question was which program won't run for very big no. input becauseof stack overfow . a. i only (ans.) b. ii only c. i& ii both . c. none

709 struct a { int a; char b; int c; }

union b

Page 110: c_test

{ char a; int b; int c; }; which is correct . a. size of a is always diff. form size of b.(ans.) b. size of a is always same form size of b. c. we can't say anything because of not-homogeneous (not in ordered) d. size of a can be same if ... ]. The following variable is available in file1.c

710main(){ int x=10,y=15; x=x++; y=++y; printf("%d %d\n",x,y);}

----------------------------------------------------------------------

711int x;main(){ int x=0; { int x=10; x++; change_value(x); x++; Modify_value(); printf("First output: %d\n",x); } x++; change_value(x); printf("Second Output : %d\n",x); Modify_value(); printf("Third Output : %d\n",x);}

Modify_value(){ return (x+=10);}

change_value(){ return(x+=1);}

----------------------------------------------------------------------------712

main(){ int x=20,y=35;

Page 111: c_test

x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y);}

-----------------------------------------------------------------------

713main(){ char *p1="Name"; char *p2; p2=(char *)malloc(20); while(*p2++=*p1++); printf("%s\n",p2);}----------------------------------------------------------------------

714main(){ int x=5; printf("%d %d %d\n",x,x<<2,x>>2);}

--------------------------------------------------------------------715

#define swap1(a,b) a=a+b;b=a-b;a=a-b;main(){ int x=5,y=10; swap1(x,y); printf("%d %d\n",x,y); swap2(x,y); printf("%d %d\n",x,y);}716

int swap2(int a,int b){ int temp; temp=a; b=a; a=temp; return;}----------------------------------------------------------------------

717main(){ char *ptr = "Ramco Systems"; (*ptr)++; printf("%s\n",ptr); ptr++; printf("%s\n",ptr);}

---------------------------------------------------------------------718#include<stdio.h>main(){ char s1[]="Ramco"; char s2[]="Systems"; s1=s2;

Page 112: c_test

printf("%s",s1);}

-----------------------------------------------------------------

720#include<stdio.h>main(){ char *p1; char *p2; p1=(char *) malloc(25); p2=(char *) malloc(25); strcpy(p1,"Ramco"); strcpy(p2,"Systems"); strcat(p1,p2); printf("%s",p1);}

721 typedef struct{ char *; nodeptr next; } * nodeptr ;

What does nodeptr stand for?

722 What does. int *x[](); means ?

723. struct list{ int x; struct list *next; }*head; the struct head.x =100 Is the above assignment to pointer is correct or wrong ?

Ans. Wrong

724.What is the output of the following ? int i; i=1; i=i+2*i++; printf(%d,i);

Ans. 4

Q725. FILE *fp1,*fp2; fp1=fopen("one","w") fp2=fopen("one","w") fputc('A',fp1) fputc('B',fp2) fclose(fp1) fclose(fp2)}a.error b. c. d.

Ans. no error. But It will over writes on same file.

What are the output(s) for the following ?

Page 113: c_test

Q726. #include<malloc.h> char *f() {char *s=malloc(8); strcpy(s,"goodbye")} main() { char *f(); printf("%c",*f()='A'); }

Q727. #define MAN(x,y) (x)>(y)?(x):(y) { int i=10;j=5;k=0; k= MAX(i++,++j) printf(%d %d %d %d,i,j,k) }

Ans. 10 5 0

Q728. a=10;b=5; c=3;d=3; if(a<b)&&(c=d++) printf(%d %d %d %d a,b,c,d) else printf("%d %d %d %d a,b,c,d);

Q729. #include<stdarg.h> show(int t,va_list ptr1) { int a,x,i; a=va_arg(ptr1,int) printf("\n %d",a) } display(char) { int x; listptr; va_star(otr,s); n=va_arg(ptr,int); show(x,ptr); } main() { display("hello",4,12,13,14,44); }

Q730. main() { printf("hello"); fork(); }

Q731. main() { int i = 10; printf(" %d %d %d \n", ++i, i++, ++i); }

Page 114: c_test

Q732. #include<stdio.h> main() { int *p, *c, i; i = 5; p = (int*) (malloc(sizeof(i))); printf("\n%d",*p); *p = 10; printf("\n%d %d",i,*p); c = (int*) calloc(2); printf("\n%d\n",*c); }

Q733. #define MAX(x,y) (x) >(y)?(x):(y) main() { int i=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); }

Q734. #include <stdio.h> main() { enum _tag{ left=10, right, front=100, back}; printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back); }

Q735. main() { int a=10,b=20; a>=5?b=100:b=200; printf("%d\n",b); }

Q736. #define PRINT(int) printf("int = %d ",int) main() { int x,y,z; x=03;y=02;z=01; PRINT(x^x); z<<=3;PRINT(x); y>>=3;PRINT(y); }

Q737. #include<stdio.h> main() { char s[] = "Bouquets and Brickbats"; printf("\n%c, ",*(&s[2])); printf("%s, ",s+5); printf("\n%s",s); printf("\n%c",*(s+2)); }

Page 115: c_test

Q738. main() { struct s1 { char *str; struct s1 *ptr; }; static struct s1 arr[] = { {"Hyderabad",arr+1}, {"Bangalore",arr+2}, {"Delhi",arr} }; struct s1 *p[3]; int i; for(i=0;i<=2;i++) p[i] = arr[i].ptr;

printf("%s\n",(*p)->str); printf("%s\n",(++*p)->str); printf("%s\n",((*p)++)->str); }

Q739.main() { char *p = "hello world!"; p[0] = 'H'; printf("%s",p); }