TECHNICAL SECTION Q1. typedef struct{ char *; nodeptr next; } * nodeptr ; What does nodeptr stand for? Q2. What does. int *x[](); means ? Q3. 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 Q4.What is the output of the following ? int i; i=1; i=i+2*i++; printf(%d,i); Ans. 4 Q5. 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 ? Q6. #include char *f() {char *s=malloc(8); strcpy(s,"goodbye")} main() { char *f(); printf("%c",*f()='A'); } Q7. #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 Q8. a=10;b=5; c=3;d=3; if(a 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); } Q10. main() { printf("hello"); fork(); } Q11. main() { int i = 10; printf(" %d %d %d \n", ++i, i++, ++i); } Q12. #include 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); } Q13. #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); } Q14. #include 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); } Q15. main() { int a=10,b=20; a>=5?b=100:b=200; printf("%d\n",b); } Q16. #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); } Q17. #include main() { char s[] = "Bouquets and Brickbats"; printf("\n%c, ",*(&s[2])); printf("%s, ",s+5); printf("\n%s",s); printf("\n%c",*(s+2)); } Q18. 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); } Q19. .main() { char *p = "hello world!"; p[0] = 'H'; printf("%s",p); } Ramco Sample C Test Paper Home Back To Ramco Page 1) Find the output for the following C program main() { char *p1="Name"; char *p2; p2=(char *)malloc(20); while(*p2++=*p1++); printf("%s\n",p2); } Ans. An empty string 2) Find the output for the following C program main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); } Ans. 57 94 3) Find the output for the following C program main() { int x=5; printf("%d %d %d\n",x,x<<2,x>>2); } Ans. 5 20 1 4) Find the output for the following C program #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 5) Find the output for the following C program main() { char *ptr = "Ramco Systems"; (*ptr)++; printf("%s\n",ptr); ptr++; printf("%s\n",ptr); } Ans. Samco Systems 6) Find the output for the following C program #include main() { char s1[]="Ramco"; char s2[]="Systems"; s1=s2; printf("%s",s1); } Ans. Compilation error giving it cannot be an modifiable 'lvalue' 7) Find the output for the following C program #include 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 8) Find the output for the following C program given that [1]. The following variable is available in file1.c static int average_float; Ans. All the functions in the file1.c can access the variable 9) Find the output for the following C program # define TRUE 0 some code while(TRUE) { some code } Ans. This won't go into the loop as TRUE is defined as 0 10) Find the output for the following C program main() { 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(x); printf("Third Output : %d\n",x); } Modify_value() { return (x+=10); } change_value() { return(x+=1); } Ans. 12 1 1 11) Find the output for the following C program main() { int x=10,y=15; x=x++; y=++y; printf("%d %d\n",x,y); } Ans. 11 16 12) Find the output for the following C program main() { int a=0; if(a=0) printf("Ramco Systems\n"); printf("Ramco Systems\n"); } Ans. Ony one time "Ramco Systems" will be printed 13) Find the output for the following C program #include 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 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); } Q15) Find the output for the following C program #include void main(void); { int a[10]; printf("%d",((a+9) + (a+1))); } Q16) Find the output for the following C program #include void main(void) { struct s{ int x; float y; }s1={25,45.00}; union u{ int x; float y; } u1; u1=(union u)s1; printf("%d and %f",u1.x,u1.y); } Q17) Find the output for the following C program #include 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"); } } Q18) Find the output for the following C program #include 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); } Q19) Find the output for the following C program #include void main(void); { char numbers[5][6]={"Zero","One","Two","Three","Four"}; printf("%s is %c",&numbers[4][0],numbers[0][0]); } Q20) 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() { int i; for(i=0;i<5;i++) if (bags[i]==20) return(bags+i); printf("Error!"); exit(0); } Q21) Find the output for the following C program #include 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); } Q22) Find the output for the following C program #include 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); } Q23) Find the output for the following C program #include static int i=5; void main(void) { int sum=0; do { sum+=(1/i); }while(0 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) { int tempval=oldval; oldval=newval; newval=tempval; } Q25) Find the output for the following C program #include void main(void); { int i=100,j=20; i++=j; i*=j; printf("%d\t%d\n",i,j); } Q26) Find the output for the following C program #include 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++); } Q27) Find the output for the following C program #include 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); Q28) Find the output for the following C program #include 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) { int i; for(i=0;i void main(void); void print(void); { print(); } void f1(void) { printf("\nf1():"); } Q30) 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()."); } Q31) Find the output for the following C program #include 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--); } Q32) Find the output for the following C program #include void main(void); typedef struct NType { int i; char c; long x; } NewType; void main(void) { 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); } Q33) Find the output for the following C program #include 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); } 1.What would be the output of the following program. #include main() { extern int a; printf("%d",a);; } int a=20; (a) 20 (b) 0 (c) garbage value (d) error!! 2.What would be the output of the following program. main() { int a[5]={2,3}; printf("\n %d %d %d",a[2],a[3],a[4]); } (a) garbage value (b) 2 3 3 (c) 3 2 2 (d) 0 0 0 3.What would be the output of the following program. main() { inti=-3,j=2,k=0,m; m=++i&&++j||++k; printf("\n %d %d %d %d",i,j,k,m); } (a) -2 3 0 1 (b) -3 2 0 1 (c) -2 3 1 1 (d) error 4.What would be the output of the following program. main() { int a,b; a=sumdig(123); b=sumdig(123); printf("%d %d",a,b); } sumdig(int n) { static int s=0; int d; if(n!=0) { d=n%10; n=(n-d)/10; s=s+d; sumdig(n); } else return(s); } (a) 12 6 (b) 6 12 (c) 3 15 (d) error 5.What would be the output of the following program. #define CUBE(x) (x*x*x) main() { int a,b=3; a=CUBE(b++); printf("\n %d %d",a,b); } (a) 64 4 (b) 27 4 (c) 27 6 (d) 64 6 6.What would be the output of the following program. main() { const int x=get(); printf("%d",x); } get() { return(20); } (a) 20 (b) garbage value (c) error (d) 0 7.A function has this prototype void f1(int **x), How will you call this function? (a) int **a; (b) int a; (c) int *a; (d) int a=5; f1(a); f1(&a); f1(&a); f1(&&a); 8.pointout the error, if any, in the for loop main() { int l=1; for(;;) { printf("%d",l++); if(l>10) break; } } (a) The condition in the for loop is a must (b) The two semicolons should be dropped (c) The for loop should be replaced by awhile loop (d) No error 9.Can the following piece of code be executed? int main(void) { char strA[10]="compile",strB[10]; my_strcpy(strB,strA); puts(strB); } char * my_strcpy(char *destination,char *source) { char *p=destination; while(*source!='\0') { *p++=*source++; } *p='\0'; return destination; } (a) Compilation will only give a warning but will proceed to execute & will display "compile" (b) The compilation error char *(char *,char *) differs in levels of indirection from 'int()' will occur (c) Yes & it will print compile on the screen (d) None of the above 10.What would be the output of the following program. #include main() { char str[5]="fast"; static char *ptr_to_array = str; printf("%s",ptr_to_array); } (a) Compilation will only give a warning but will proceed to execute & will display "fast" (b) display "fast" on screen (c) will give a compilation error (d) none of the above 11.What would be the output of the following program. main() { int num,*p; num=5; p=# printf("%d",*p); } (a) 6 (b) 5 (c) junk value (d) compilation error 12.What would be the output of the following program. main() { int a[3]={2,3,4}; char *p; p=a; p=(char *)((int *)p+1); printf("%d",p); } (a) 2 (b) 0 (c) junk value (d) 3 13.What would be the output of the following program. main() { int i=10; fn(i); printf("%d",i); } fn(int i) { return ++i; } (a) 10 (b) 11 (c) 12 (d) Compilation error 14. What will be the value of i & j after the loop isexecuted?
for(i=0,j=0;i<5,j<25;i++,j++) (a) i=4,j= 24 (b) i=24,j= 24 (c) i=25,j= 25 (d) i=5,j=25 15.What would be the output of the following program. main() { int i,j; i=10; j=sizeof(++i); printf("%d",i); } (a) 11 (b) 10 (c) 4 (d) compilation error 16.What would be the output of the following program. main() { int i=7; printf("%d\n",i++*i++); } (a) 49 (b) 56 (c) 72 (d) compilation error 17. What will the printf print? main() { char *p,*f(); p=f(); printf("f() returns:%s\n",p); } char *f() { char result[80]; strcpy(result,"anything will do"); return (result); } (a) f() returns: anything will do (b) f() returns: (c) compilation error (d) The printf statement is not going to be executed 18.How many times the following program would print 'Jamboree'? main() { printf("\n Jamboree"); main(); } (a) infinite number of times (b) 32767 times (c) 65535 times (d) till the stack does not overflow 19.Notice the error in the default statement in the code snippet below.Will it give a compilation error? main() { int a=10,j; j=fn(a); switch(j) { case 30: printf("the value is 30"); break; case 50: printf("the value is 50"); break; default:printf("the value is not 30 or 50"); } } fn(int a) { return (++a); } (a) Will display "the value is 30" (b) Will display "The value is not 30 or 50" (c) Yes a compilation error would happen (d) No compilation errors but there will be no output on the screen 20.What would be the output of the following program. main() { struct emp { char name[20]; int age; float sal; }; struct emp e = {"tiger"}; printf("\n %d %f",e.age,e.sal); } (a) 0 0.000000 (b) Garbage values (c) Error (d) none of the above **********regarding the aditi questions **************** points regarding c: 1. the value of any variable will change as it is executing ex: for(i=0,j=0;i<5,j<25;i++,j++) %% the value of i and j will be 25 25 when it is printed 2. the value of any variable(i) will depend on the any values given or specified Ex: main() { extern int a; printf(a); } int a=5; %% the value of a is 5 3. the value of any variable will not depend on the function i.e scope EX: main() { int a; pirntf(a); } scope() { int a=4; } %% the value of a is not 4 but a junk 4. when main is recursed the execution will continue untill the stack gets overflow. 5. size of char * is 2 C Puzzles : Questions and Answers - Level 1 Questions L1.Q1 : Write the output of the following program #include #define ABC 20 #define XYZ 10 #define XXX ABC - XYZ void main() { int a; a = XXX * 10; printf("%d\n", a); } Solution for L1.Q1 L1.Q2 : Write the output of this program #include #define calc(a, b) (a * b) / (a - b) void main() { int a = 20, b = 10; printf("%d\n", calc(a + 4, b -2)); } Solution for L1.Q2 L1.Q3 : What will be output of the following program ? #include void main() { int cnt = 5, a; do { a /= cnt; } while (cnt --); printf ("%d\n", a); } Solution for L1.Q3 L1.Q4 : Print the output of this program #include void main() { int a, b, c, abc = 0; a = b = c = 40; if (c) { int abc; abc = a*b+c; } printf ("c = %d, abc = %d\n", c, abc); } Solution for L1.Q4 L1.Q5 : Print the output of this program #include main() { int k = 5; if (++k < 5 && k++/5 || ++k <= 8); printf("%d\n", k); } Solution for L1.Q5 L1.Q6 : What is the output of this program ? #include void fn(int, int); main() { int a = 5; printf("Main : %d %d\n", a++, ++a); fn(a, a++); } void fn(int a, int b) { printf("Fn : a = %d \t b = %d\n", a, b); } Solution for L1.Q6 Answers L1.A1 Solution for L1.Q1 a = xxx * 10 which is => a = ABC - XYZ * 10 => a = 20 - 10 * 10 => a = 20 - 100 => a = -80 L1.A2 Solution for L1.Q2 Actual substitution is like this : calc(20+4, 10 -2) is calculated as follows (20+4 * 10-2) / (20+4 - 10-2) (20+40-2) / 12 58 / 12 = 4.8 since it is printed in %d the ans is 4 L1.A3 Solution for L1.Q3 This problem will compile properly, but it will give run time error. It will give divide-by-zero error. Look in to the do loop portion do { a /= cnt; } while (cnt --); when the 'cnt' value is 1, it is decremented in 'while ( cnt --)' and on next reference of 'cnt' it becomes zero. a /= cnt; /* ie. a /= 0 */ which leads to divide-by-zero error. L1.A4 Solution for L1.Q4 the result will be c = 40 and abc = 0; because the scope of the variable 'abc' inside if(c) {.. } is not valid out side that if (.) { .. }. L1.A5 Solution for L1.Q5 The answer is 7. The first condition ++k < 5 is checked and it is false (Now k = 6). So, it checks the 3rd condition (or condition ++k <= 8) and (now k = 7) it is true. At this point k value is incremented by twice, hence the value of k becomes 7. L1.A6 Solution for L1.Q6 The solution depends on the implementation of stack. (Depends on OS) In some machines the arguments are passed from left to right to the stack. In this case the result will be Main : 5 7 Fn : 7 7 Other machines the arguments may be passed from right to left to the stack. In that case the result will be Main : 6 6 Fn : 8 7 Goto C Puzzle · level 2 · level 3 1.void main() { int d=5; printf("%f",d); } Ans: Undefined 2. 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 3. void main() { char *s="\12345s\n"; printf("%d",sizeof(s)); } Ans: 6 4. void main() { unsigned i=1; /* unsigned char k= -1 => k=255; */ signed j=-1; /* char k= -1 => k=65535 */ /* unsigned or signed int k= -1 =>k=65535 */ if(ij) printf("greater"); else if(i==j) printf("equal"); } Ans: less 5. void main() { float j; j=1000*1000; printf("%f",j); } 1. 1000000 2. Overflow 3. Error 4. None Ans: 4 6. How do you declare an array of N pointers to functions returning pointers to functions returning pointers to characters? Ans: The first part of this question can be answered in at least three ways: 1. char *(*(*a[N])())(); 2. Build the declaration up incrementally, using typedefs: typedef char *pc; /* pointer to char */ typedef pc fpc(); /* function returning pointer to char */ typedef fpc *pfpc; /* pointer to above */ typedef pfpc fpfpc(); /* function returning... */ typedef fpfpc *pfpfpc; /* pointer to... */ pfpfpc a[N]; /* array of... */ 3. Use the cdecl program, which turns English into C and vice versa: cdecl> declare a as array of pointer to function returning pointer to function returning pointer to char char *(*(*a[])())() cdecl can also explain complicated declarations, help with casts, and indicate which set of parentheses the arguments go in (for complicated function definitions, like the one above). Any good book on C should explain how to read these complicated C declarations "inside out" to understand them ("declaration mimics use"). The pointer-to-function declarations in the examples above have not included parameter type information. When the parameters have complicated types, declarations can *really* get messy. (Modern versions of cdecl can help here, too.) 7. A structure pointer is defined of the type time . With 3 fields min,sec hours having pointers to intergers. Write the way to initialize the 2nd element to 10. 8. In the above question an array of pointers is declared. Write the statement to initialize the 3rd element of the 2 element to 10; 9. 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. 10. void main() { int i=7; printf("%d",i++*i++); } Ans: 56 11. #define one 0 #ifdef one printf("one is defined "); #ifndef one printf("one is not defined "); Ans: "one is defined" 12. void main() { intcount=10,*temp,sum=0; temp=&count; *temp=20; temp=∑ *temp=count; printf("%d %d %d ",count,*temp,sum); } Ans: 20 20 20 13. There was question in c working only on unix machine with pattern matching. 14. what is alloca() Ans : It allocates and frees memory after use/after getting out of scope 15. main() { static i=3; printf("%d",i--); return i>0 ? main():0; } Ans: 321 16. 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. 17. 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" . What does the following program print? #include int sum,count; void main(void) {< BR> for(count=5;sum+=--count;) printf("%d",sum); } a. The pgm goes to an infinite loop b. Prints 4791010974 c. Prints 4791001974 d. Prints 5802112085 e. Not sure 2. What is the output of the following program? #include void main(void) { int i;< BR> for(i=2;i<=7;i++) printf("%5d",fno()); } fno() { staticintf1=1,f2=1,f3; return(f3=f1+f2,f1=f2,f2=f3); } a. produce syntax errors b. 2 3 5 8 13 21 will be displayed c. 2 2 2 2 2 2 will be displayed d. none of the above e. Not sure 3. What is the output of the following program? #include void main (void) { int x = 0x1234; int y = 0x5678; x = x & 0x5678; y = y | 0x1234; x = x^y; printf("%x\t",x); x = x | 0x5678; y = y & 0x1234; y = y^x; printf("%x\t",y); } a. bbb3 bbb7 b. bbb7 bbb3 c. 444c 4448 d. 4448 444c e. Not sure 4. What does the following program print? #include void main (void) { int x; x = 0; if (x=0) printf ("Value of x is 0"); else printf ("Value of x is not 0"); } a. print value of x is 0 b. print value of x is not 0 c. does not print anything on the screen d. there is a syntax error in the if statement e. Not sure 5. What is the output of the following program? #include #include int foo(char *); void main (void) { char arr[100] = {"Welcome to Mistral"}; foo (arr); } foo (char *x) { printf ("%d\t",strlen (x)); printf ("%d\t",sizeof(x)); return0; } a. 100 100 b. 18 100 c. 18 18 d. 18 2 e. Not sure 6. What is the output of the following program? #include display() { printf ("\n Hello World"); return 0; } void main (void) { int (* func_ptr) (); func_ptr = display; printf ("\n %u",func_ptr); (* func_ptr) (); } a. it prints the address of the function display and prints Hello World on the screen b. it prints Hello World two times on the screen c. it prints only the address of the fuction display on the screen d. there is an error in the program e. Not sure 7. What is the output of the following program? #include void main (void) { int i = 0; char ch = 'A'; do putchar (ch); while(i++ < 5 || ++ch <= 'F'); } a. ABCDEF will be displayed b. AAAAAABCDEF will displayed c. character 'A' will be displayed infinitely d. none e. Not sure 8. What is the output of the following program? #include #define sum (a,b,c) a+b+c #define avg (a,b,c) sum(a,b,c)/3 #define geq (a,b,c) avg(a,b,c) >= 60 #define lee (a,b,c) avg(a,b,c) <= 60 #define des (a,b,c,d) (d==1?geq(a,b,c):lee(a,b,c)) void main (void) { int num = 70; char ch = '0'; float f = 2.0; if des(num,ch,f,0) puts ("lee.."); else puts("geq..."); } a. syntax error b. geq... will be displayed c. lee.. will be displayed d. none e. Not sure 9. Which of the following statement is correct? a. sizeof('*') is equal to sizeof(int) b. sizeof('*') is equal to sizeof(char) c. sizeof('*') is equal to sizeof(double) d. none e. Not sure 10. What does the following program print? #include char *rev(int val); void main(void) { extern char dec[]; printf ("%c", *rev); } char *rev (int val) { char dec[]="abcde"; return dec; } a. prints abcde b. prints the address of the array dec c. prints garbage, address of the local variable should not returned d. print a e. Not sure 11. What does the following program print? void main(void) { int i; static int k; if(k=='0') printf("one"); else if(k== 48) printf("two"); else printf("three"); } a. prints one b. prints two c. prints three d. prints one three e. Not sure 12. What does the following program print? #include void main(void) { enum sub { chemistry, maths, physics }; struct result { char name[30]; enum sub sc; }; struct result my_res; strcpy (my_res.name,"Patrick"); my_res.sc=physics; printf("name: %s\n",my_res.name); printf("pass in subject: %d\n",my_res.sc); } a. name: Patrick b. name: Patrick c. name: Patrick pass in subject: 2 pass in subject:3 pass in subject:0 d. gives compilation errors e. Not sure 13. What does printf("%s",_FILE_); and printf("%d",_LINE_); do? a. the first printf prints the name of the file and the second printf prints the line no: of the second printf in the file b. _FILE_ and _LINE_ are not valid parameters to printf function c. linker errors will be generated d. compiler errors will be generated e. Not sure 14. What is the output of the following program? #include void swap (int x, int y, int t) { t = x; x = y; y = t; printf ("x inside swap: %d\t y inside swap : %d\n",x,y); } void main(void) { int x; int y; int t; x = 99; y = 100; swap (x,y,t); printf ("x inside main:%d\t y inside main: %d",x,y); } a. x inside swap : 100 y inside swap : 99 x inside main : 100 y inside main : 99 b. x inside swap : 100 y inside swap : 99 x inside main : 99 y inside main : 100 c. x inside swap : 99 y inside swap : 100 x inside main : 99 y inside main : 100 d. x inside swap : 99 y inside swap : 100 x inside main : 100 y inside main : 99 e. Not sure 15. Consider the following statements: i) " while loop " is top tested loop ii) " for loop " is bottom tested loop iii) " do - while loop" is top tested loop iv) " while loop" and "do - while loop " are top tested loops. Which among the above statements are false? a. i only b. i & ii c. iii & i d. ii, iii & iv e. Not sure 16. Consider the following piece of code: char *p = "MISTRAL"; printf ("%c\t", *(++p)); p -=1; printf ("%c\t", *(p++)); Now, what does the two printf's display? a. M M b. M I c. I M d. M S e. Not sure 17. What does the following program print? #include struct my_struct { int p:1; int q:1; int r:6; int s:2; }; struct my_struct bigstruct; struct my_struct1 { char m:1; }; struct my_struct1 small struct; void main (void) { printf ("%d %d\n",sizeof (bigstruct),sizeof (smallstruct)); } a. 10 1 b. 2 2 c. 2 1 d. 1 1 e. Not sure 18. Consider the following piece of code: FILE *fp; fp = fopen("myfile.dat","r"); Now fp points to a. the first character in the file. b. a structure which contains a char pointer which points to the first character in the file. c. the name of the file. d. none of the above. e. Not sure. 19. What does the following program print? #include #define SQR (x) (x*x) void main(void) { int a,b=3; a = SQR (b+2); } a. 25 b. 11 c. 17 d. 21 e. Not sure. 20. What does the declaration do? int (*mist) (void *, void *); a. declares mist as a function that takes two void * arguments and returns a pointer to an int. b. declares mist as a pointer to a function that has two void * arguments and returns an int. c. declares mist as a function that takes two void * arguments and returns an int. d. there is a syntax error in the declaration. e. Not sure. 21. What does the following program print? #include void main (void) { int mat [5][5],i,j; int *p; p = & mat [0][0]; for (i=0;i<5;i++) for (j=0;j<5;j++) mat[i][j] = i+j; printf ("%d\t", sizeof(mat)); < BR> i=4;j=5; printf( "%d", *(p+i+j)); } a. 25 9 b. 25 5 c. 50 9 d. 50 5 e. Not sure 22. What is the output of the following program? #include void main (void) { short x = 0x3333; short y = 0x4321; long z = x; z = z << 16; z = z | y; printf("%1x\t",z); z = y; z = z >> 16; z = z | x; printf("%1x\t",z); z = x; y = x && y; z = y; printf("%1x\t",z); } a. 43213333 3333 1 b. 33334321 4321 4321 c. 33334321 3333 1 d. 43213333 4321 4321 e. Not sure 23. What is the output of the following program? #include void main (void) { char *p = "Bangalore"; #if 0 printf ("%s", p); #endif } a. syntax error #if cannot be used inside main function b. prints Bangalore on the screen c. does not print anything on the screen d. program gives an error "undefined symbol if" e. Not sure 24. If x is declared as an integer, y is declared as float, consider the following expression: y = *(float *)&x; Which one of the following statments is true? a. the program containing the expression produces compilation errors; b. the program containing the expression produces runtime errors; c. the program containing the expression compiles and runs without any errors; d. none of the above e. Not sure 25. What is the return type of calloc function? a. int * b. void * c. no return type: return type is void d. int e. Not sure 21. 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. 22. 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. 24. 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. 25. 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) {....} 26. 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. 27. 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 28. 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 29. 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 30. 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} . @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 1) Find the output for the following C program main() { char *p1="Name"; char *p2; p2=(char *)malloc(20); while(*p2++=*p1++); printf("%s\n",p2); } Ans. An empty string 2) Find the output for the following C program main() { intx=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); } Ans. 57 94 3) Find the output for the following C program main() { int x=5; printf("%d %d %d\n",x,x<<2,x>>2); } Ans. 5 20 1 4) Find the output for the following C program < P>#defineswap1(a,b)a=a+b;b=a-b;a=a-b; main() { intx=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 5) Find the output for the following C program main() { char *ptr = "Ramco Systems"; (*ptr)++; printf("%s\n",ptr); ptr++; printf("%s\n",ptr); } Ans. Samco Systems 6) Find the output for the following C program #include main() { char s1[]="Ramco"; char s2[]="Systems"; s1=s2; printf("%s",s1); } Ans. Compilation error giving it cannot be an modifiable 'lvalue' 7) Find the output for the following C program #include 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 8) Find the output for the following C program given that [1]. The following variable is available in file1.c static int average_float; Ans. All the functions in the file1.c can access the variable 9) Find the output for the following C program # define TRUE 0 some code while(TRUE) { some code } Ans. This won't go into the loop as TRUE is defined as 0 10) Find the output for the following C program main() { 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(x); printf("Third Output : %d\n",x); } Modify_value() { return (x+=10); } change_value() { return(x+=1); } Ans. 12 1 1 11) Find the output for the following C program main() { int x=10,y=15; x=x++; y=++y; printf("%d %d\n",x,y); } Ans. 11 16 12) Find the output for the following C program main() { int a=0; if(a=0) printf("Ramco Systems\n"); printf("Ramco Systems\n"); } Ans. Ony one time "Ramco Systems" will be printed 13) Find the output for the following C program #include 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 void main(void); int printf(const char*,...); void main(void) { inti=100,j=10,k=20; -- int sum; float ave; charmyformat[]="ave=%.2f"; sum=i+j+k; ave=sum/3.0; printf(myformat,ave); } Q15) Find the output for the following C program #include void main(void); { int a[10]; printf("%d",((a+9) + (a+1))); } Q16) Find the output for the following C program #include void main(void) { struct s{ int x; float y; }s1={25,45.00}; union u{ int x; float y; } u1; u1=(union u)s1; printf("%d and %f",u1.x,u1.y); } Q17) Find the output for the following C program #include 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"); } } Q18) Find the output for the following C program #include 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); } Q19) Find the output for the following C program #include void main(void); { char numbers[5][6]={"Zero","One","Two","Three","Four"}; printf("%s is %c",&numbers[4][0],numbers[0][0]); } Q20) 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() { int i; for(i=0;i<5;i++) if (bags[i]==20) return(bags+i); printf("Error!"); exit(0); } Q21) Find the output for the following C program #include void main(void) { inty,z;
intx=y=z=10; int f=x; float ans=0.0; f *=x*y; ans=x/3.0+y/3; printf("%d %.2f",f,ans); } Q22) Find the output for the following C program #include void main(void); { doubledbl=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); } Q23) Find the output for the following C program #include static int i=5; void main(void) { int sum=0; do { sum+=(1/i); }while(0 void main(void) { intoldvar=25,newvar=-25; int swap(int,int); swap(oldvar,newvar); printf("Numbers are %d\t%d",newvar,oldvar); } int swap(int oldval,int newval) { int tempval=oldval; oldval=newval; newval=tempval; } Q25) Find the output for the following C program #include void main(void); { inti=100,j=20; i++=j; i*=j; printf("%d\t%d\n",i,j); } Q26) Find the output for the following C program #include 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++); } Q27) Find the output for the following C program #include 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); Q28) Find the output for the following C program #include 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) { int i; for(i=0;i void main(void); void print(void); { print(); } void f1(void) { printf("\nf1():"); } Q30) 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()."); } Q31) Find the output for the following C program #include 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--); } Q32) Find the output for the following C program #include void main(void); typedef struct NType { int i; char c; long x; } NewType; void main(void) { 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); } Q33) Find the output for the following C program #include 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); } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1. Point out error, if any, in the following program main() { int i=1; switch(i) { case 1: printf("\nRadioactive cats have 18 half-lives"); break; case 1*2+4: printf("\nBottle for rent -inquire within"); break; } } Ans. No error. Constant expression like 1*2+4 are acceptable in cases of a switch. 2. Point out the error, if any, in the following program main() { int a=10,b; a>= 5 ? b=100 : b=200; printf("\n%d",b); } Ans. lvalue required in function main(). The second assignment should be written in parenthesis as follows: a>= 5 ? b=100 : (b=200); 3. In the following code, in which order the functions would be called? a= f1(23,14)*f2(12/4)+f3(); a) f1, f2, f3 b) f3, f2, f1 c) The order may vary from compiler to compiler d) None of the above 4. What would be the output of the following program? main() { int i=4; switch(i) { default: printf("\n A mouse is an elephant built by the Japanese"); case 1: printf(" Breeding rabbits is a hair raising experience"); break; case 2: printf("\n Friction is a drag"); break; case 3: printf("\n If practice make perfect, then nobody's perfect"); } } a) A mouse is an elephant built by the Japanese b) Breeding rabbits is a hare raising experience c) All of the above ans: d) None of the above 5. What is the output of the following program? #define SQR(x) (x*x) main() { int a,b=3; a= SQR(b+2); printf("%d",a); } a) 25 b) 11 c) error d) garbage value 6. In which line of the following, an error would be reported? 1. #define CIRCUM(R) (3.14*R*R); 2. main() 3. { 4. float r=1.0,c; 5. c= CIRCUM(r); 6. printf("\n%f",c); 7. if(CIRCUM(r))==6.28) 8. printf("\nGobbledygook"); 9. } a) line 1 b) line 5 c) line 6 d) line 7 7. What is the type of the variable b in the following declaration? #define FLOATPTR float* FLOATPTR a,b; a) float b) float pointer c) int d) int pointer 8. In the following code; #include main() { FILE *fp; fp= fopen("trial","r"); } fp points to: a) The first character in the file. b) A structure which contains a "char" pointer which points to the first character in the file. c) The name of the file. d) None of the above. 9. We should not read after a write to a file without an intervening call to fflush(), fseek() or rewind() < TRUE/FALSE> Ans. True 10. If the program (myprog) is run from the command line as myprog 1 2 3 , What would be the output? main(int argc, char *argv[]) { int i; for(i=0;i0) printf("%s",*++argv); } a) myprog monday tuesday wednesday thursday b) monday tuesday wednesday thursday c) myprog tuesday thursday d) None of the above 13. In the following code, is p2 an integer or an integer pointer? typedef int* ptr ptr p1,p2; Ans. Integer pointer 14. Point out the error in the following program main() { const int x; x=128; printf("%d",x); } Ans. x should have been initialized where it is declared. 15. What would be the output of the following program? main() { int y=128; const int x=y; printf("%d",x); } ans: a) 128 b) Garbage value c) Error d) 0 16. What is the difference between the following declarations? const char *s; char const *s; Ans. No difference 17. What is the difference between the following declarations? const char *const s; char const *const s; Ans. No difference 18. What would be the output of the following program? main() { char near * near *ptr1; char near * far *ptr2; char near * huge *ptr3; printf("%d %d %d",sizeof(ptr1),sizeof(ptr2),sizeof(ptr3)); } a) 1 1 1 b) 1 2 4 c) 2 4 4 d) 4 4 4 19. If the following program (myprog) is run from the command line as myprog friday tuesday sunday, What would be the output? main(int argc, char*argv[]) { printf("%c",**++argv); } a) m b) f c) myprog d) friday 20. If the following program (myprog) is run from the command line as myprog friday tuesday sunday, What would be the output? main(int argc, char *argv[]) { printf("%c",*++argv[1]); } a) r b) f c) m d) y 21. If the following program (myprog) is run from the command line as myprog friday tuesday sunday, What would be the output? main(int argc, char *argv[]) { while(sizeofargv) printf("%s",argv[--sizeofargv]); } a) myprog friday tuesday sunday b) myprog friday tuesday c) sunday tuesday friday myprog d) sunday tuesday friday 22. Point out the error in the following program main() { int a=10; void f(); a=f(); printf("\n%d",a); } void f() { printf("\nHi"); } Ans. The program is trying to collect the value of a "void" function into an integer variable. 23. In the following program how would you print 50 using p? main() { int a[]={10, 20, 30, 40, 50}; char *p; p= (char*) a; } Ans. printf("\n%d",*((int*)p+4)); 24. Would the following program compile? main() { int a=10,*j; void *k;< BR> j=k=&a; j++; k++; printf("\n%u%u",j,k); } a) Yes b) No, the format is incorrect c) No, the arithmetic operation is not permitted on void pointers d) No, the arithmetic operation is not permitted on pointers 25. According to ANSI specifications which is the correct way of declaring main() when it receives command line arguments? a) main(int argc, char *argv[]) b) main(argc,argv) int argc; char *argv[]; c) main() {int argc; char *argv[]; } d) None of the above 26. What error would the following function give on compilation? f(int a, int b) { int a; a=20; return a; } a) missing parenthesis in the return statement b) The function should be declared as int f(int a, int b) c) redeclaration of a d) None of the above 27. Point out the error in the following program main() { const char *fun(); *fun()='A'; } const char *fun() { return "Hello"; } Ans. fun() returns to a "const char" pointer which cannot be modified 28. What would be the output of the following program? main() { const int x=5; int *ptrx; ptrx=&x; *ptrx=10; printf("%d",x); } a) 5 b) 10 ans:c) Error d) Garbage value 29. A switch statement cannot include a) constants as arguments b) constant expression as arguments c) string as an argument d) None of the above 30. How long the following program will run? main() { printf("\nSonata Software"); main(); } a) infinite loop b) until the stack overflows ) All of the above d) None of the above 31. On combining the following statements, you will get char*p; p=malloc(100); a) char *p= malloc(100) b) p= (char*)malloc(100) c) All of the above d) None of the above 32. What is the output of the following program? main() { int n=5; printf("\nn=%*d",n,n); } a) n=5 ans: b)n= 5 c) n=5 d) error ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1. The C language terminator is (a) semicolon (b) colon (c) period (d) exclamation mark 2. What is false about the following -- A compound statement is (a) A set of simple statements (b) Demarcated on either side by curly brackets (c) Can be used in place of simple statement (d) A C function is not a compound statement. 3. 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 4. Main must be written as (a) The first function in the program (b) Second function in the program (c) Last function in the program (d) Any where in the program 5. 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 6. Write one statement equivalent to the following two statements: x=sqr(a); return(x); Choose from one of the alternatives (a) return(sqr(a)); (b) printf("sqr(a)"); (c) return(a*a*a); (d) printf("%d",sqr(a)); 7. Which of the following about the C comments is incorrect ? (a) Comments can go over multiple lines (b) Comments can start any where in the line (c) A line can contain comments with out any language statements (d) Comments can occur within comments 8. What is the value of y in the following code? x=7; y=0; if(x=6) y=7; else y=1; (a) 7 (b) 0 (c) 1 (d) 6 9. Read the function conv() given below conv(int t) { int u; u=5/9 * (t-32); return(u); } What is returned (a) 15 (b) 0 (c) 16.1 (d) 29 10. Which of the following represents true statement either x is in the range of 10 and 50 or y is zero (a) x >= 10 && x <= 50 || y = = 0 (b) x<50 (c) y!=10 && x>=50 (d) None of these 11. Which of the following is not an infinite loop ? (a) while(1)\{ ....} (b) for(;;){...} (c) x=0; (d) # define TRUE 0 do{ /*x unaltered within the loop*/ ... .....}while(x = = 0); while(TRUE){ ....} 12. What does the following function print? func(int i) { if(i%2)return 0; else return 1; } main() { int =3; i=func(i); i=func(i); printf("%d",i); } (a) 3 (b) 1 (c) 0 (d) 2 13. How does the C compiler interpret the following two statements p=p+x; q=q+y; (a) p= p+x; (b)p=p+xq=q+y; (c)p= p+xq; (d)p=p+x/q=q+y; q=q+y; q=q+y; For questions 14,15,16,17 use the following alternatives: a.int b.char c.string d.float 14. '9' 15. "1 e 02" 16. 10e05 17. 15 18. Read the folllowing code # define MAX 100 # define MIN 100 .... .... if(x>MAX) x=1; else if(x>=b (d) a**=b 27. What is y value of the code if input x=10 y=5; if (x==10) else if(x==9) else y=8; (a)9 (b)8 (c)6 (d)7 28. What does the following code do? fn(int n, int p, int r) { static int a=p; switch(n) { case 4:a+=a*r; case 3:a+=a*r; case 2:a+=a*r; case 1:a+=a*r; } } (a) computes simple interest for one year (b) computes amount on compound interest for 1 to 4 years (c) computes simple interest for four year (d) computes compound interest for 1 year 29. a=0; while(a<5) printf("%d\\n",a++); How many times does the loop occurs? (a) infinite (b)5 (c)4 (d)6 30. How many times does the loop iterated ? for(i=0;i=10;i+=2) printf("Hi\\n"); (a)10 (b) 2 (c) 5 (d) None of these 31. What is incorrect among the following A recursive function (a) calls itself (b) is equivalent to a loop (c) has a termination condition (d) does not have a return value at all 32. Which of the following go out of the loop if expn 2 becoming false (a) while(expn 1)\{...if(expn 2)continue;} (b) while(!expn 1)\{if(expn 2)continue;...} (c) do{..if(expn 1)continue;..}while(expn 2); (d) while(!expn 2)\{if(expn 1)continue;..\} 33. Consider the following program main() { unsigned int i=10; while(i>=0) { printf("%u",i) i--; } } How many times the loop will get executed (a)10 (b)9 (c)11 (d) infinite 34.Pick out the odd one out (a) malloc() (b) calloc() (c) free() (d) realloc() 35.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 36. # define prod(a,b)=a*b main() { int x=2; int y=3; printf("%d",prod(x+2,y-10)); } the output of the program is (a) 8 (b) 6 (c) 7 (d) None 37.Consider the following program segment int n,sum=1; switch(n) { case 2:sum=sum+2; case 3:sum*=2; break; default:sum=0; } If n=2, what is the value of sum (a) 0 (b) 6 (c) 3 (d) None of these 38. Identify the incorrect one 1.if(c=1) 2.if(c!=3) 3.if(a0) { x=func(i); i--; } int func(int n) { static sum=0; sum=sum+n; return(sum); } } The final value of x is (a) 6 (b) 8 (c) 1 (d) 3 43. Int *a[5] refers to (a) array of pointers (b) pointer to an array (c) pointer to a pointer (d) none of these 44.Which of the following statements is incorrect (a) typedef struct new { int n1; char n2; } DATA; (b) typedef struct { int n3; char *n4; }ICE; (c) typedef union { int n5; float n6; } UDT; (d) #typedef union { int n7; float n8; } TUDAT; ************************************************************ Q1. typedef struct{ char *; nodeptr next; } * nodeptr ; What does nodeptr stand for? Q2. What does. int *x[](); means ? Q3. 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 Q4.What is the output of the following ? int i; i=1; i=i+2*i++; printf(%d,i); Ans. 4 Q5. 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 ? Q6. #include char *f() {char *s=malloc(8); strcpy(s,"goodbye")} main() { char *f(); printf("%c",*f()='A'); } Q7. #define MAN(x,y) (x)>(y)?(x):(y) { inti=10;j=5;k=0; k= MAX(i++,++j) printf(%d %d %d %d,i,j,k) } Ans. 10 5 0 Q8. a=10;b= 5;c=3;d=3; if(a 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); } Q10. main() { printf("hello"); fork(); } Q11. main() { int i = 10; printf(" %d %d %d \n", ++i, i++, ++i); } ans:? 13 11 11 Q12. #include 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); } Q13. #define MAX(x,y) (x) >(y)?(x):(y) main() { inti=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); } Q14. #include 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); } Q15. main() { inta=10,b=20;
a>=5?b=100:b=200; printf("%d\n",b); } Q16. #define PRINT(int) printf("int = %d ",int) main() {< BR> intx,y,z;
x=03;y=02;z=01; PRINT(x^x); z<<=3;PRINT(x); y>>=3;PRINT(y); } Q17. #include main() { char s[] = "Bouquets and Brickbats"; printf("\n%c, ",*(&s[2])); printf("%s, ",s+5); printf("\n%s",s); printf("\n%c",*(s+2)); } Q18. 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; < BR> 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); } Q19. .main() { char *p = "hello world!"; p[0] = 'H'; printf("%s",p); } ans: Hello world! $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ **********regarding the aditi questions **************** points regarding c: 1. the value of any variable will change as it is executing ex: for(i=0,j=0;i<5,j<25;i++,j++) %% the value of i and j will be 25 25 when it is printed 2. the value of any variable(i) will depend on the any values given or specified Ex: main() { extern int a; printf(a); } int a=5; %% the value of a is 5 3. the value of any variable will not depend on the function i.e scope EX: main() { int a; pirntf(a); } scope() { int a=4; } %% the value of a is not 4 but a junk 4. when main is recursed the execution will continue untill the stack gets overflow. 5. size of char * is 2 ************************************************************************ #include #include void main() { clrscr(); static int c=5; //op is 1 see here there is no reintialization printf("%d",c--); if(c) main(); getch(); } /* exploring c notes */ #include #include /*void function(a,b) //no need for declaration of a,b; { printf("%d%d",a,b); } */ void main() { clrscr(); int a,b; //printf("%d%c\n"); //garbage values //printf("%d%f",4,4); //floating point not linked /* scanf(" %d ",&a); // it asks for two values printf("%d",a); scanf("%dhai iam fine %d",&a,&a); //gets only one values will print the following continously : printf(" hai iam syed \ iam testing for contigious \ printing using printf statement\ using the backslash operator"); int d=500,c; b=100; if(!d >=400) b=300; c=200; printf("%d\t%d",b,c); int x=2,y=5; // *= should come togeather y *=x; printf("%d",y); int x=3,z; z=x++ +x++; // op :5,6 printf("%d%d",x,z); int x=3,z; z=++x*++x*++x; // op :216 printf("%d",z); return(10,20); // will return the second value i.e is 20 function(4,5); int z=3; printf("%d",printf("%d%d%d%d%d",z,z,z,z,z)); //will print no of %d in II printf statement float z=4.999999; printf("%d",z); // junk values pointer operations: ------------------- int *p; char *p1; int q=3; char r=4; p=&q; printf("%p\t%p\n",p,&q); p1=&r; printf("%p\t%p\n",p1,&r); printf("%d%d",*p1,*p); */ printf(5+"fascimile"); ans:mile **************************************************************************** /**********************size of various datatypes************************/ #include #include void main() { clrscr(); printf("size of int is : %d",sizeof(int)); printf("\nsize of char is : %d",sizeof(char)); printf("\nsize of float is : %d",sizeof(float)); printf("\nsize of double is : %d",sizeof(double)); printf("\nsize of long is : %d",sizeof(long)); printf("\nsize of unsigned int is : %d",sizeof(unsigned int)); printf("\nsize of signed int is : %d",sizeof(signed int)); printf("\nsize of short is : %d",sizeof(short)); printf("\nsize of int* is : %d",sizeof(int*)); printf("\nsize of char* is : %d",sizeof(char*)); printf("\nsize of float* is : %d",sizeof(float*)); printf("\nsize of double* is : %d",sizeof(double*)); getch(); } /* answer size of int is : 2 size of char is : 1 size of float is : 4 size of double is : 8 size of long is : 4 size of unsigned int is : 2 size of signed int is : 2 size of short is : 2 size of int* is : 2 size of char* is : 2 size of float* is : 2 size of double* is : 2 */ ********************************************************************* #include #include enum number { a=-1, b=4, c,d,e,}; main() { clrscr(); number n; //0p : 7 printf("%d",e); getch(); } ******************************************************************* #include #include void change(int *b,int n) { int i; for(i=0;i #include #include //void main (){clrscr(); /* 24 int n, sum=5; n=2; switch(n) { case 2:sum=sum-2; case 3:sum*=5; //prints 15 break; default:sum=0; } printf("%d",sum); 25 while(0) { printf("it is not an infinite loop "); } 26 int i=0; for(i=0;i<20;i++) { switch(i){ case 0: i+=5; case 1: // 16 21 i+=2; case 5: i+=5; default: i+=4; break; } printf("%d\t",i); } 27 func(int i) { if(i%2) return 0; else return 1; } main() { clrscr(); //answer : 1 int i=3; i=func(i); i=func(i); printf("%d",i); 28 char*g() { static char x[1024]; return x; } void main() { clrscr(); char * g1="First String"; strcpy(g(),g1); g1=g(); //printf(g1); strcpy(g1,"Second String"); printf("Answer is:%s", g()); 29) int a[5]={1,3,6,7,0}; int *b; b=&a[2]; printf("%d",b[-1]); */ getch(); } ************************************************************************* /* size of structures */ #include #include struct ash { int a:1; //both int values are 1 int b:2; char c; //char is 1 double d; //double is 8 totally =10 }ash1; void main() { clrscr(); printf("\n %d ",sizeof(ash1)); getch(); } /* note : size of struct is 2 becos int a:1 is bitfield allocation when higher allocation than int is given it counts but when u give char it wont count for its size ************************************************************************** #include #include /* void main() { clrscr(); printf(" Hello \o is the world "); // ans:Hello o is the world getch(); } void main() { int i=2; clrscr(); printf("%old %old %old %old ",i, i++,i--,i++); // right to left evaluation getch(); } */ void main(){ int n,temp,result; clrscr(); n=7623; { temp=n/10; result=temp*10+ result; n=n/10; } getch(); } ************************************************************************ #include #include /**************** G:\ash\Qpapers\papers\c questions\ADITI ****************** 1 #include #include main() { clrscr(); extern int a; clrscr(); printf("%d",a);; } int a=20; answer :20 2 int a[5]={2,3}; printf("\n %d %d %d",a[2],a[3],a[4]); ans: 0 0 0 3 int i=-3,j=2,k=0,m; m=++i&&++j||++k; printf("\n %d %d %d %d",i,j,k,m); ans : -2 3 0 1 4 int sumdig(int); int a,b; a=sumdig(123); b=sumdig(123); printf("%d %d",a, b); getch(); } sumdig(int n) { static int s=0; int d; if(n!=0) { d=n%10; n=(n-d)/10; s=s+d; sumdig(n); } else return(s); } answer :6 12 another: int a=1,b,d=1; b=a%10; d=(d-b)%10; printf("%d %d" ,b,d); 5 #define CUBE(x) (x*x*x) main() { int a,b=3; a=CUBE(b++); printf("\n %d %d",a,b); // 27 6 getch(); } main() { clrscr(); char str[5]="fast"; static char *ptr_to_array = str; printf("%s",ptr_to_array); ANSWER :FAST int num,*p; num=5; p=# printf("%d",*p); ANSWER :5 12 int a[3]={2,3,4}; char *p; p=a; p=(char *)((int *)p+1); printf("%d",p); 13 fn(int i) { return ++i; } void main() { clrscr(); int i=10; fn(i); printf("%d",i); getch(); } ANSWER : 10 14 for(int i=0,j=0;i<5,j<25;i++,j++) {} printf ("%d %d ", i,j) ; ASNWER : 25 25 15 int i,j; i=10; j=sizeof(++i); printf("%d",i); ANSWER :10 20 struct emp { char name[20]; int age; float sal; }; struct emp e = {"tiger"}; printf("\n %d %f",e.age,e.sal); ANSWER : 0 0.0000 getch(); } */ ************************************************************************ /**************************G:\ash\Qpapers\papers\c questions*************** 6:49 PM 5/10/2003 */ #include #include void main() { clrscr(); /* 3 char *s="\12345s\n"; printf("%d",sizeof(s)); //ANSWER: 2 4 unsigned i=1; // unsigned char k= -1 => k=255; signed j=-1; // char k= -1 => k=65535 // unsigned or signed int k= -1 =>k=65535 if(ij) printf("greater"); else //ANSWER : LESS if(i==j) printf("equal"); 5 float j; //printf("%f",j); j=1000*1000; printf("%f",j); //ANSWER :16960.000000 // WHEN 100*100 GIVES 10000.000000 12 */ int count=10,*temp,sum=0; temp=&count; printf("%d %d ",*temp,count,sum); *temp=20; printf("%d %d ",*temp,count,sum); temp=∑ printf("%d %d ",*temp,count,sum); *temp=count; printf("%d %d %d ",count,*temp,sum); getch(); } ************************************************************************ #include #include #include void main() { clrscr(); /* 1 int sum,count; void main(void) { clrscr(); for(count=5;sum+=--count;) //Prints 4791010974 printf("%d",sum); 2 int fno() { static int f1=1,f2=1,f3; return(f3=f1+f2,f1=f2,f2=f3); } 3. void main(){clrscr(); int i; for(i=2;i<=7;i++) printf("%5d",fno());getch();} 4 int x; x = 0; if (x=0) printf ("Value of x is 0"); else printf ("Value of x is not 0"); //ANSWER :X IS NOT 0 5 int foo(char *); void main (void) { char arr[100] = {"Welcome to Mistral"}; foo (arr); } foo (char *x) { printf ("%d\t",strlen (x)); printf ("%d\t",sizeof(x)); // answer :18 2 return 0; } 6 display() { printf ("\n Hello World"); //answer : HELLO WORLD return 0; } void main (void) { int (* func_ptr) (); func_ptr = display; printf ("\n %u",func_ptr); (* func_ptr) (); } 7 int i = 0; char ch = 'A'; do putchar (ch); while(i++ < 5 || ++ch <= 'F'); 11 int i; static int k; if(k=='0') printf("one"); else if(k== 48) printf("two"); else printf("three"); //answer :three 12 enum sub { chemistry, maths, physics }; struct result { char name[30]; enum sub sc; }; struct result my_res; strcpy (my_res.name,"Patrick"); my_res.sc=physics; printf("name: %s\n",my_res.name); printf("pass in subject: %d\n",my_res.sc); // patrick 2 13 printf("%s",_FILE_); printf("%d",_LINE_); //undefined symbol 14 void swap (int x, int y, int t) { t = x; x = y; y = t; printf ("x inside swap: %d\t y inside swap : %d\n",x,y); } void main(void) { clrscr(); int x; int y; int t; x = 99; y = 100; swap (x,y,t); printf ("x inside main:%d\t y inside main: %d",x,y); 16 char *p = "MISTRAL"; printf ("%c\t", *(++p)); p -=1; printf ("%c\t", *(p++)); // I M 17 struct my_struct { int p:1; int q:1; int r:6; int s:2; }; struct my_struct bigstruct; struct my_struct1 { char m:1; //size is 2 1 }; struct my_struct1 smallstruct; void main (void) { clrscr(); printf ("%d %d\n",sizeof (bigstruct),sizeof (smallstruct)); 19 #define SQR(x) (x*x) b+2*b+2 void main(void) { clrscr(); int a,b=3; a = SQR(b+2); //11 printf("%d",a); 20 int mat [5][5],i,j; int *p; p =&mat [0][0]; for (i=0;i<5;i++) for (j=0;j<5;j++) mat[i][j] = i+j; printf ("%d\t", sizeof(mat)); i=4;j=5; printf( "%d", *(p+ffi+j)); 23 char *p = "Bangalore"; #if 0 //doesnot print anything printf ("%s", p); #endif 24 float y; int x; y = *(float *)&x; getch();} *************************************************************************** /*****************G:\ash\Qpapers\papers\c questions\ramco*******************/ #include #include #include void main(void){clrscr(); /* 10) int x; int Modify_value() { return (x+=10); } int change_value() { return(x+=1); } void main() { clrscr(); x++; change_value(); x++; Modify_value(); printf("First output: %d\n",x); x++; change_value(); printf("Second Output : %d\n",x); Modify_value(); printf("Third Output : %d\n",x); 12 int a=0; if(a=0) printf("Ramco1 Systems\n"); printf("Ramco Systems\n"); 14 void main(void); int printf(const char*,...); void main(void) { clrscr(); 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); 15 int a[10]; printf("%d",((a+9) + (a+1))); 16 struct s{ int x; float y; }s1={25,45.00}; union u{ int x; float y; } u1; struct s2; // cannot type cast u1= (union u)s1; printf("%d and %f",u1.x,u1.y); 17 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"); // welcome to all default:printf("\n"); } 18 int fn(void); void print(int,int(*)()); int i=10; void main(void) { int i=20; print(i,fn); getch(); } void print(int i,int (*fn1)()) { printf("%d\n",(*fn1)()); } int fn(void) { return(i-=5); } 19 char numbers[5][6]={"Zero","One","Two","Three","Four"}; // four is zint bags[5]={20,5,20,3,20}; printf("%s is %c",&numbers[4][0],numbers[0][0]); 20 int bags[5]={20,5,20,3,20}; void main(void) { clrscr(); int pos=5,*next(); *next()=pos; printf("%d %d %d",pos,*next(),bags[0]); getch(); } int *next() { int i; for(i=0;i<5;i++) if (bags[i]==20) return(bags+i); // 5 20 5 printf("Error!"); exit(0); } 21 int y,z; int x=y=z=10; int f=x; float ans=0.0; f *=x*y; ans=x/3.0+y/3; // 1000 6.33 printf("%d %.2f",f,ans); 22 double dbl=20.4530,d=4.5710,dblvar3; double dbln(void); dblvar3=dbln(); printf("%.2f\t%.2f\t%.2f\n",dbl,d,dblvar3); getch(); } double dbln(void) { double dblvar3,dbl,d; dbl=dblvar3=4.5; printf("%ld",d); return(dbl+d+dblvar3); } 23 static int i=5; void main(void) { int sum=0; do { sum+=(1/i); printf("%d",sum); }while(0=5?b=100:b=200; printf("%d\n",b); getch();} ************************************************************************ /*******************scope of variables ********************** 1. when a varible is globally declared the value will be always = 0 2. variable scope depends on the function 3. when a variable is declared static its value is 0 */ #include #include extern int i=1; void test() { printf("%d",i); } void main() { clrscr(); static int i; printf("%d",i); test(); getch(); } ************************************************************************** 1. Question: The C language terminator is (a) semicolon (b) colon (c) period (d) exclamation mark Ans: 1 2. Question: Which of the following makes the statement incorrect? Description: A compound statement is: (a) a set of simple statements (b) demarcated on either side by curly brackets (c) can be used in place of simple statement (d) a C function is not a compound statement. Ans: 2 3. Question: Which of the following statements on C functions is true? (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 Ans: 1 4. Question: The function main( ) must be written (a) as the first function in the program (b) as the second function in the program (c) as the last function in the program (d) any where in the program Ans: 4 5. Question: Which of the following about automatic variables within a function is true? (a) Its type must be declared before using the variable (b) They are not local (c) They are not initialized to zero (d) They are global Ans: 3 6. Question: Pick a single statement equivalent to the following two statements. Description: x = sqr(a); return(x); (a) return(sqr(a)); (b) printf("sqr(a)"); (c) return(a*a*a); (d) printf("%d",sqr(a)); Ans: 1 7. Question: Which of the following about C comments is incorrect? (a) Comments can go over multiple lines (b) Comments can start any where in the line (c) A line can contain comments with out any language statements (d) Comments can occur within comments Ans: 4 8. Question: What is the final value of y, in the following code? Description: x = 7; y = 0; if ( x = 6 ) y = 7; else y = 1; (a) 7 (b) 0 (c) 1 (d) 6 Ans: 1 9. Question: Read the function ‘conv( )’ given below and say what is returned. Description: conv ( int t ) { int u; u = 5/9 * (t - 32); return(u); } (a) 15 (b) 0 (c) 16.1 (d) 29 Ans: 2 10. Question: Which of the following represents the statement given? Description: Either x is in the range of 10 and 50 or y is zero (a) x >= 10 && x <= 50 || y ==0 (b) x < 50 (c) y != 10 && x >= 50 (d) None of the above Ans: 1 11. Question: Which of the following is not an infinite loop? (a) while(1) { … } (b) for ( ; ; ) { … } (c) x = 0; do{ /*x unaltered within the loop*/ … }while (x ==0); (d) # define TRUE 0 while (TRUE) { … } Ans: 4 12. Question: What does the following piece of code output? Description: 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 Ans: 2 13. Question: How does the C compiler interpret the following two statements? Description: p = p + x; q = q + y; (a) p=p+x; q=q+y (b) p=p+xq=q+y (c) p=p+xq; q=q+y (d) p=p+x/q=q+y 14. Question: What is the data type of the following: Description: '9' (a) int (b) char (c) string (d) float Ans: 2 15. Question: What is the data type of the following: Description: "1e-02" (a) int (b) char (c) string (d) float Ans: 3 16. Question: What is the data type of the following: Description: 10e05 (a) int (b) char (c) string (d) float Ans: 4 17. Question: What is the data type of the following: Description: 15 (a) int (b) char (c) string (d) float Ans: 1 18. Question: If initially x is 200, what is its value after executing this code? Description: # define MAX 100 # define MIN 100 main ( ) { … … if ( x > MAX ) x = 1; else if ( x < MIN ) x = -1; x = 50; } (a) 200 (b) 1 (c) -1 (d) 50 Ans: 4 19. Question: What is the value of ’l’? Description: A memory of 20 bytes is allocated to a string declared as char *s and then the following two statements are executed: s = "Entrance" l = strlen(s); (a) 20 (b) 8 (c) 9 (d) 21 Ans: 2 20. Question: To access the 6th element of the array which of the following is incorrect? Description: int a[50]; int *pa; pa = a; (a) *(a+5) (b) a[5] (c) pa[5] (d) *(*pa + 5} Ans: 4 21. Question: What does the given code print? Description: struct num nam{ int no; char name[25]; }; struct num nam n1[] = {{12,"Fred"},{15,"Martin"},{8,"Peter"},{11,Nicholas"}}; … … printf("%d,%d",n1[2].no,(*(n1 + 2).no + 1)); (a) 8,9 (b) 9,9 (c) 8,8 (d) 8,unpredictable value Ans: 1 22. Question: Identify the incorrect expression (a) a = b = 3 = 4; (b) a = b = c = d = 0; (c) float a = int b = 3.5; (d) int a; float b; a = b = 3.5; Ans: 1 23. Question: Regarding the scope of the variables, identify the incorrect statement: (a) Automatic variables are automatically initialized to 0 (b) Static variables are automatically initialized to 0 (c) The address of a register variable is not accessible (d) Static variables cannot be initialized with any expression Ans: 1 24. Question: The given statement is equivalent to which of the following? Description: cond 1?cond 2?cond 3?:exp 1:exp 2:exp 3:exp 4; (a)if cond 1 exp 1; else if cond 2 exp 2; else if cond 3 exp 3; else exp 4; (b)if cond 1 if cond 2 if cond 3 exp 1; else exp 2; else exp 3; else exp 4; (c)if cond 1 && cond 2 && cond 3 exp 1|exp 2|exp 3|exp 4; (d)if cond 3 exp 1; else if cond 2 exp 2; else if cond 3 exp 3; else exp 4; Ans: 2 25. Question: The operator for exponentiation is (a) ** (b) ^ (c) % (d) not available Ans: 4 26. Question: Which of the following is invalid? (a) a += b (b) a *= b (c) a >>= b (d) a **= b Ans: 4 27. Question: What is y value of the code if input x = 10? Description: y = 5; if (x ==10) else if (x ==9) else y = 8; (a)9 (b)8 (c)6 (d)None of the above Ans: 4 28. Question: What does the given code do? Description: fn ( int n, int p, int r) { static int a = p; switch (n) { case 4: a += a*r; case 3: a += a*r; case 2: a += a*r; case 1: a += a*r; } } (a) computes simple interest for one year (b) computes amount on compound interest for 1 to 4 years (c) computes simple interest for four year (d) computes compound interest for 1 year Ans: 2 29. Question: How many times does the loop occurs? Description: a = 0; while ( a < 5 ) printf("%d\n",a++); (a) Infinite (b) 5 (c) 4 (d) 6 Ans: 2 30. Question: How many times does the loop iterate? Description: for ( i = 0 ; i = 10 ; i += 2 ) printf("Hi\n"); (a)10 (b) 2 (c) 5 (d) None of the above Ans: 4 31. Question: Which of the following makes the statement incorrect? Description: A recursive function (a) calls itself (b) is equivalent to a loop (c) has a termination condition (d) does not have a return value at all Ans: 4 32. Question: Which of the following loop are exit if ‘expn 2’ becomes false? (a) while ( expn 1) {… if ( expn 2 ) continue; } (b) while ( !expn 1 ) { if ( expn 2 ) continue;…} (c) do {… if ( expn 1 ) continue;…} while ( expn 2 ); (d) while ( !expn 2 ) { if ( expn 1 ) continue;…} Ans: 3 33. Question: How many times will the loop get executed? Description: main ( ) { unsigned int i = 10; while ( i >= 0 ) { printf("%u",i) i--; } } (a) 10 (b) 9 (c) 11 (d) infinite Ans: 4 34. Question: Pick the odd one out. (a) malloc() (b) calloc() (c) free() (d) realloc() Ans: 4 35. Question: The value of b[-1] is: Description: main ( ) { int a[5] = { 1,3,6,7,0 }; int *b; b = &a[2]; } (a) 1 (b) 3 (c) -6 (d) None of the above Ans: 2 36. Question: What is the output of the given program? Description: # define prod ( a , b ) = a * b main ( ) { int x = 2; int y = 3; printf("%d",prod (x+2,y-10) ); } (a) -28 (b) +28 (c) 11 (d) None of the above Ans: 4 37. Question: If n = 2, what is the value of ‘sum’ Description: int n,sum = 1; switch (n) { case 2 : sum = sum + 2; case 3 : sum *= 2; break; default : sum = 0; } (a) 0 (b) 6 (c) 3 (d) None of these Ans: 2 38. Question: Identify the incorrect ‘if’ statement. Description: 1. if ( c = 1 ) 2. if ( c != 3 ) 3. if ( a < b ) then 4. if ( c == 1 ) (a) 1 only (b) 1&3 (c) 3 only (d) All of the above Ans: 3 39. Question: The format specified for hexadecimal is (a) %d (b) %o (c) %x (d) %u Ans: 3 40. Question: Find the output of the given program Description: main ( ) { int *p, x = 5; p=&x printf("%d",++*p); } (a) 5 (b) 6 (c) 0 (d) None of the above Ans: 2 41. Question: The final value of x is: Description: int func(int n) { static sum = 0; sum = sum+n; return(sum); } main ( ) { int i = 3, x; while ( i > 0 ) { x = func( i ); i--; } } (a) 6 (b) 2 (c) 1 (d) 3 Ans: 1 42. Question: int *a[5] refers to: (a) array of integer pointers (b) pointer to an integer array (c) pointer to a pointer (d) None of the above Ans: 1 43. Question: Which of the given statements is incorrect? (a) typedef struct new{ int n1; char n2; }DATA; (b) typedef struct { int n3; char *n4; }ICE; (c) typedef union { int n5; float n6; }UDT; (d) #typedef union { int n7; float n8; }TUDAT; Ans: 4 44. Question: Which of these is an invalid data name? a) [wd_count] b) wd_count c) w4count d) wdcountabcd Ans: 1 45. Question: What is the value of ‘i’ after the given expression? Description: i = 1; i << 1 % 2 a) 0 b) 1 c) 2 d) 3 Ans: 2 46. Question: What is the value of ‘i’ after the given expression? Description: i = 1; i = (i <<= 1 % 2) a) 0 b) 1 c) 2 d) erroneous syntax Ans: 3 47. Question: What is the value of b? Description: int *a, b; b = 1; a = &b; b = *a + 1 - *a + 3 a) 0 b) 1 c) 4 d) None of the above Ans: 3 48. Question: Which of the following makes the statement correct? Description: C allows a) only call by value b) only call by reference c) both call by value & reference d) only call by value and sometimes call by reference Ans: 3 49. Question: The given statement is: Description: ‘The size of a structure is always equal to the sum of the sizes of its members’ a) valid b) invalid c) can't say d) None of the above Ans: 1 50. Question: How many ‘x’ are printed? Description: for (i = 0, j = 10 ; i < j ; i++, j--) printf("x"); a) 10 b) 5 c) 4 d) none Ans: 2 51. Question: What is the output? Description: swap (int i, int j) { int temp; temp = i; i = j; j = temp; } main () { int i = 2, j = 3, k = 1; swap (i, j) printf ("%d %d", i, j); } a) 1, 4 b) 2, 3 c) 1, 3 d) 2, 4 Ans: 2 52. Question: What is the value of *p? Description: int i, b[] = {1, 2, 3, 4, 5}, *p; p = b; ++*p; p += 2; a) 2 b) 3 c) 4 d) 5 Ans: 2 53. Question: What is the value of (p - (&p - 2))? a) 0 b) 2 c) 3 d) None of the above Ans: 4 54. Question: What does b stand for in the given expression? Description: x = fopen (b, c); a) pointer to a character array which contains the filename b) filename within double quotes c) any one of the above d) None of the above Ans: 3 55. Question: For ‘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 allocated c) x points to the memory allocated d) none of the above Ans: 3 56. Question: 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;} int; Ans: 2 57. Question: What is the output? Description: union { int no; char ch; } u; u.ch = '2'; u.no = 0; printf ("%d", u.ch); a) 2 b) 0 c) NULL character d) None of the above Ans: 2 58. Question: Which of these are valid declarations? Description: i) union { int i; int j; }; ii) union u_tag { int i; int j; }; iii) union { int i; int j; FILE k; }; iv) union { int i; int j; } u; a) all correct b) i, ii, iv c) ii & iv d) None of the above Ans: 2 59. Question: p and q are pointers to the same type of data items. Which of these are valid? Description: i) *(p + q) ii) *(p - q) iii) *p - *q a) all b) i and ii c) iii is valid sometimes d) None of the above Ans: 1 60. Question: Which of the given statements are true? Description: i) pointers can be added ii) pointers can be subtracted iii) integers can be added to pointers a) only i b) only iii c) both i & iii d) i,ii & iii Ans: 4 61. Question: What is the output? Description: int i = 20; printf ("%x", i); a) x14 b) 14 c) 20 d) None of the above Ans: 2 62. Question: What is the output? Description: main ( ) { char *name = "name"; change (name); printf ("%s", name); } change (char *name) { char *nm = "newname"; name = nm; } a) name b) newname c) ‘name = nm’ not valid d) function call invalid Ans: 1 63. Question: What is the output? Description: char name[] = {'n', 'a', 'm', 'e'}; printf ("name = \n%s", name); a) name = name b) name = followed by junk characters c) name = name d) None of the above Ans: 3 64. Question: What is the final value of b? Description: int a = 1, b = 2; if (a = 0) b = 0; else b *= 10; a) 0 b) 20 c) 2 d) None of the above Ans: 1 65. Question: What is the value of x after the given statements? Description: int x = 2, y = 2, z = 1; if (x = y%2) … else … a) 0 b) 2 c) 1 d) None of the above Ans: 1 66. Question: What is the output if initially n = -24? Description: printd (int n) { if (n < 0) { printf ("-"); n = -n; } if (n % 10) printf ("%d", n); else printf ("%d", n/10); printf ("%d", n); } a) -24 b) 24 c) -2424 d) -224 Ans: 3 67. Question: If the input stream contains "4.2 3 2.3 ..." what will x and y contain after scanf? Description: float x, y, z; scanf ("%f %f", &x, &y); a) 4.2, 3.0 b) 4.2, 2.3 c) 4.2, 32.3 d) None of the above Ans: 1 68. Question: What is the output? Description: #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)); a) 32 b) 21 c) 31 d) 13 Ans: 2 69. Question: Which are valid references? Description: struct adr { char *name; char *city; int zip; }; struct adr *adradr; i) adr->name ii) adradr->name iii) adr.zip iv) adradr.zip a) only i b) only ii c) both i & iii d) both ii & iv Ans: 4 70. Question: What is the output if the given program ‘prog.c’ is invoked as ‘prog arg1’? Description: main (x, y) int x, char *y[]; { printf ("%d %s", x, y[1]); } a) 1 prog b) 1 arg1 c) 2 prog d) 2 arg1 Ans: 2 71. Question: Which of s, t and u are available to a function present in another file? Description: extern int s; global int t; static int u; main ( ) {…} a) only s b) s & t c) s, t & u d) None of the above Ans: 1 72. Question: For which of the functions is ‘a’ available? Description: main ( ) {…} int a; f1 ( ) {…} f2 ( ) {…} a) All of them b) only f2 c) only f1 d) both f1 and f2 Ans: 1 73. Question: What is the value of ‘a’ after ‘mixup’? Description: int a = 'a'; char b = ‘b’, c = ‘c’; main ( ) { mixup (a, b, &c); } mixup (int p1, char *p2, char **p3) { int *temp; temp = &p1; p1 = p2; p2 = temp; } a) 97 b) 98 c) 99 d) None of the above Ans: 1 74. Question: What is the value of ‘b’ after ‘mixup’? Description: int a = 'a'; char b = ‘b’, c = ‘c’; main ( ) { mixup (a, b, &c); } mixup (int p1, char *p2, char **p3) { int *temp; temp = &p1; p1 = p2; p2 = temp; } a) a b) b c) c d) None of the above Ans: 2 75. Question: What is the output? Description: main () { char s[] = "T.C.S", *A; print(s); } print (char *p) { while (*p != '\0') { if (*p != ‘.’) printf ("%c", *p); p++; } } a) T.C.S b) TCS c) . . d) None of the above Ans: 2 76. Question: If the input is "1a1b1cE", what is the output? Description: main ( ) { int ones, twos, threes, others; int c; ones = twos = threes = others = 0; while ((c = getchar ()) != ‘E’) { switch (c) { case '1': ++ones; case '2': ++twos; case '3': ++threes; break; default: ++others; break; } } printf ("%d%d", ones, others); } a) 13 b) 23 c) 33 d) 31 Ans: 3 77. Question: What will the output be if x = 1234? Description: void output (int x) { if (x != 0) { output(x / 16); putchar("0123456789ABCDEF"[x % 16]); } else putchar('\n'); } a) 1234 b) 3C1 c) 4D2 d) Will not compile Ans: 3 78. Question: What is the output? Description: main( ) { int a=1, b=2, c=3, *pointer; pointer = &c; a = c/*pointer; b = c; printf ("a=%d b=%d",a,b); } a) 1 3 b) 3 3 c) 3 2 d) Error Ans: 4 79. Question: What is the output? Description: #define scanf "%s is a string" main() { printf(scanf,scanf); } a) scanf is a string b) %s is a string c) %s is a string is a string d) None of the above Ans: 3 80. Question: What is the output? Description: enum mode {green, red, orange, blue, white}; main ( ) { int a = green + 1; printf("%d,%d,%d",a,green,red); } a) 2,1,3 b) 2,1,2 c) 1,0,1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% int f1( ) int f2( ) int f3( ) int f4( ) int main ( int argc, char *argv[] ) { printf(f1( )); } int f1( ) { return f2( ) ? f3( ) : f4( ) ; } int f2( ) return f3( ) ? f4( ) : 100 ; int f3( ) return 2 ; int f4( ) return 5 ; ( a) 5 ( b ) 2 ( c ) 0 ( d ) 100 ans : b int i = 0, *j ; int a; int *p = &a int **q= &p int *&fp = p int **&fpp = q to dereference a interm of fpp MVI A, oh equilent to in 8085 Ans : XRAA 32 bit signed integer ans : -231 to 231 -1 -asm {int 3} DMA Ans : none of the above VMS Ans : hard drive as RAM Symmetrical multitasking Re β€" emptive multitasking int a = 0, b = 0 if ( a, b++, a++) printf (a) else printf (b) ans : print the value of b = 1 mutex ( a ) synchronization ( b ) semaphore ( c ) thread ( d ) all ans : ( d ) all Sequential circuits op β€" amp ans : flipflop Class A order of clling destructors in inheritance ans : CBA Class member variables cannot be extern 16) ans : Derived D 15 1) pigeous 30 rabbit to 2) 67, 51, 52, 42, 37, - - - - - - - - ans : x = 12, y = 5 A, B, - C ans : 20 Monkey ans : 45 min 5) number is divided by 4 and 3 ans : 67 6) CODE ans : ( d ) 3452 7) number of Sqrs ans : 30 8) Which is biggest area having same perimeter ans : circle 9) A, b, c partnership c gets ans : Rs. 400 10) father β€" son age ans : 42 11) Man before mirror ans : man’s son 12) gold and silver ans : 7 : 5 13) switch on : light ans : turn on : tap 14) rat races 15) alleiviate (verbal) 16) pips & cistern ans : 7 Β½ hrs 17) Upstream & Downstream ans : 2 hrs 18) A, B, sides case, west ans : 10 miles, South west %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% d) None of the above Ans: 3 ***************************************************************************