You are on page 1of 11

C-Objectives Questions

Note:- There some questions from C,C++ and some related to Unix.
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]; 4. What is the memory allocated by the following definition? Int (*x)(); 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; main() { BAD g1; g1=1; printf("%d",g1); } 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); } 9. Give the output for the following program segment. #ifdef TRUE int I=0; #endif main() {

int j=0; printf("%d %d\n",i,j); } 10. In the following program #include<stdio.h> main() { char *pDestn,*pSource="I Love You Daddy"; pDestn=malloc(strlen(pSource)); strcpy(pDestn,pSource); printf("%s",pDestn); free(pDestn); } (a)Free() fails (b)Strcpy() fails (c)prints I love You Daddy (d)error 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); } 12. Find the output for the following C program int 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]); 13. 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++); } 14. For the following C program 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; Find value of d 15. 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 above 16. Find the output for the following C program main() { int x,j,k; j=k=6;x=2; x=j*k; printf("%d", x); } 17. Find the output for the following C program fn f(x) { if(x<=0) return;

else f(x-1)+x; } 18. 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 19. 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 20. Find the output for the following C program int x=5; y= x&y 21.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 22. 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) 23. What is the sizeof(long int) (a) 4 bytes (b) 2 bytes (c) compiler dependent (d) 8 bytes

24. Which of the function operator cannot be over loaded (a) <= (b) ?: (c) == (d) * 25. Find the output for the following C program main() { int x=2,y=6,z=6; x=y==z; printf(%d",x) } 26.Answer the questions based on the following program VOID FUNCTION(INT KK) { KK+=20; } VOID FUNCTION (INT K) INT MM,N=&M KN = K KN+-=10; } 27. 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); } (a) 20,55 (b) 35,35 (c) 25,25 (d) 55,55 28. enum number { a=-1, b= 4,c,d,e} What is the value of e ? (a) 7 (b) 4 (c) 5 (d) 15 (e) 3 30. 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;} printf("%d,",i); } } a) 0,5,9,13,17 b) 5,9,13,17 c) 12,17,22 d) 16,21 e) Syntax error Ans. (d) 31. What is the ouptut in the following program main() { char c=-64; int i=-32 unsigned int u =-16; if(c>i) { printf("pass1,");

if(c<u) printf("pass2"); else printf("Fail2"); } else printf("Fail1); if(i<u) printf("pass2"); else printf("Fail2") } a) Pass1,Pass2 b) Pass1,Fail2 c) Fail1,Pass2 d) Fail1,Fail2 e) None of these Ans. (c)

32. 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 8 c) Generate compilation error in line number 5 d) Generate compilation error in line number 7 e) Generate compilation error in line number 1 Ans. (b)

33. 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"); else printf("not same"); } a) same, MAXINT, -1 b) not same, MAXINT, -MAXINT c) same , MAXUNIT, -1 d) same, MAXUNIT, MAXUNIT e) not same, MAXINT, MAXUNIT Ans. (a) 34. 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 : string b) The string is :Oldstring c) Run time error/Core dump d) Syntax error during compilation e) None of these Ans. (b) 35. 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 : String b) Run time error/Core dump c) The string is : Oldstring d) Syntax error during compilation e) None of these 36. 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"); else printf("Fail 2"); } else { printf("Fail 1"); if(p[sizeof(p)-2]=='g') printf("Pass 2"); else printf("Fail 2"); } } a) Pass 1, Pass 2 b) Fail 1, Fail 2 c) Pass 1, Fail 2 d) Fail 1, Pass 2 e) syntax error during compilation 37. Which of the choices is true for the mentioned declaration ? const char *p; and char * const p;

a) You can't change the character in both b) First : You can't change the characterr & Second : You can;t change the pointer c) You can't change the pointer in both d) First : You can't change the pointer & Second : You can't chanage the character e) None 38. The redirection operators > and >> a) do the same function b) differ : > overwrites, while >> appends c) differ : > is used for input while >> is used for output d) differ : > write to any file while >> write only to standard output e) None of these Ans. (b)

You might also like