Sasken Technical Questions 1. main() int a = 10,*j; void *k; j = k =&a; j++; k++; printf("\n %u %u",j,k); A.compiler error B.syntax error C.memory address D.no output Explanation: cannot increment a void pointer 2. What will be the output of the program? int i; int fun1(int); int fun2(int); extern int j; int i=3; fun1(i); printf("%d,", i); fun2(i); printf("%d", i); int fun1(int j) printf("%d,", ++j); int fun2(int i) printf("%d,", ++i); int j=1;
A.3, 4, 4, 3 B.4, 3, 4, 3 C.3, 3, 4, 4 D.3, 4, 3, 4 3. main() int i =3; for(; i ++ = 0;) printf("%d",i); A.compiler error B.syntax error C.some garbage value D.no output Explanation: Lvalue required in function main 4. Point out the error in the program int f(int); int b; b = f(20); printf("%d\n", b); int f(int a) a > 20? return(10): return(20); A.Error: Prototype declaration B.No error conditional operators D.None of above C.Error: return statement cannot be used with Explanation: In a ternary operator, we cannot use the return statement. The ternary operator requires expressions but not code. 5. What will be output of following c program?
#define max printf("%d",max); A.0 B.null C.Garbage D.Compilation error 6. What will be the output of the program? int i; int fun(); while(i) fun(); main(); printf("hello\n"); int fun() printf("hi"); A.Hello B.Hi Hello C.No output D.Infinite loop 7. What will be output of following c program? void main() int i; for(i=0;i<5;i++) int x=0; printf("%d",x); x++;
A.01234 B.001234 C.0000 D.Infinite loop 8. What will be the output of the program? int x, y, z; x=y=z=1; z = ++x ++y && ++z; printf("x=%d, y=%d, z=%d\n", x, y, z); A.x=2, y=1, z=1 B.x=2, y=2, z=1 C.x=2, y=2, z=2 D.error 9. What will be output of following c program? long fu(int); char vect[]=1,2,3,4,5; void main() int i=1; i=fu(++i)+ ++vect[++i]+ ++i+fu(i++); printf("%d",i); long fu(int x) return x*3; A.31 B.32 C.33 D.34 10. What will be the output of the program? unsigned int i = 65536; while(i!= 0) printf("%d",++i); printf("\n");
A.Infinite loop B.0 1 2... 65535 C.0 1 2... 32767-32766 -32765-1 0 D.No output 11.void main() int a = 10, b =20; char x = 1, y = 0; if(a,b,x,y) printf("freshersworld"); What is the output? A.res is printed B.freshersworld is printed C.Compiler Error D.Nothing is printed 12. What is x in the following program? typedef char (*(*arrfptr[3])())[10]; arrfptr x; A.x is a pointer B.x is an array of three pointer C.x is an array of three function pointers in x declaration D.Error 13. main() char throught[2][30] = "Don't walk in front of me..",'i am not follow"; printf("%c%c,*(thought[0]9),*(*(thought 0)5)); What is the output of this program? A.kk B.int**array2 = (int**)malloc(nrows*sizeof(int*));don't walk in front of me C.i may not follow D.k
14. What will be the output of the program? int k=1; printf("%d == 1 is" "%s\n", k, k==1?"true":"false"); A.k == 1 is TRUE B.1 == 1 is TRUE C.1 == 1 is FALSE D.K == 1 is FALSE 15. main() int i=5; printf("%d",i = ++i==6); A.5 B.1 C.6 D.compiler error 16. Which files will get closed through the fclose() in the following program? FILE *fs, *ft, *fp; fp = fopen("a.c", "r"); fs = fopen("b.c", "r"); ft = fopen("c.c", "r"); fclose(fp, fs, ft); A."A.C" "B.C" "C.C" B."B.C" "C.C" C."A.C"D.Error in fclose() 17. void main() printf("sizeof(void *) = %d \n",sizeof(void*));
printf("sizeof(int *) = %d \n",sizeof(int*)); printf("sizeof(double*) = %d \n",sizeof(double*)); printf("sizeof(struct unknown *) = %d \n",sizeof(struct unknown*)); A.no out put B.compiler error C.sizeof(void *) = 2 sizeof(int *) = 2 sizeof(double *) = 2 sizeof(struct unknown *) = 2 D.syntax error 18. Which of the following statements are correct about the program below? int size, i; scanf("%d", &size); int arr[size]; for(i=1; i<=size; i++) scanf("%d", arr[i]); printf("%d", arr[i]); A.The code is erroneous since the subscript for array used in for loop is in the range 1 to size. B.The code is erroneous since the values of array are getting scanned through the loop. C.The code is erroneous since the statement declaring array is invalid. D.The code is correct and runs successfully. 19. # include char *somefun1() char temp[] ="string"; return temp; char * somefun2() char temp[] = 's','t','r','i','n','g'; return temp;
puts (somefun1()); puts(somefun2()); A.syntax error B.some garbage value C.compiler error D.no out put 20. What will be the output of the program? int fun(int(*)()); fun(main); printf("hi\n"); int fun(int (*p)()) printf("hello "); A.Infinite loop B.Hi C.Hello Hi D.Error 21. Point out the error, if any in the while loop. int i=1; while() printf("%d\n", i++); if(i>10) break; A.There should be a condition in the while loop B.There should be at least a semicolon in the while C.The while loop should be replaced with for loop. D.No error
22. What will be output of following c program? void main() int num,a=10; num=a--- -a--; printf("%d %d",num,a); A.0 8 B.0 10 C.20 8 D.-1 10 23. What will be output of following c program? float avg(float,float,float); void main() float p=1,q=2,r=-2,a; a=avg(p,(q=4,r=-12,q),r); printf("%f",a); float avg(float x,float y,float z) return (x+y+z)/3; A.0.111111 B.1.000000 C.-0.777777 D.-1.000000 24. How many times "Freshersworld" is get printed? int x; for(x=-1; x<=10; x++) if(x < 5) continue; else break; printf("freshersworld");
A.Infinite times B.11 times C.0 times D.10 times 25. What will be output of following c program? struct mystruct int a; char b; *ptr; struct mystruct ms=400,'a'; printf("%d %d",ptr->a,ptr->b); A.400 A B.400 6 C.400 97 D.0 0 26. What will be the output of the program? int i; i = scanf("%d %d", &i, &i); printf("%d\n", i); A.1 B.2 C.Garbage value D.Error: cannot assign scanf to variable Explanation: scanf() returns the number of variables to which you are provding the input. i = scanf("%d %d", &i, &i); Here Scanf() returns 2. So i = 2. printf("%d\n", i); Here it prints 2. 27. What will be output of following c program? float x; x=(int)1.1,(float)2.2,(int)3.3,5.4;
printf("%f",x); A.1.000000 B.5.400000 C.2.200000 D.3.300000 28. Point out the correct statement which correctly allocates memory dynamically for 2D array following program? int *p, i, j; /* Add statement here */ for(i=0; i<3; i++) for(j=0; j<4; j++) p[i*4+j] = i; printf("%d", p[i*4+j]); A.p = (int*) malloc(3, 4); B.p = (int*) malloc(3*sizeof(int)); C.p = malloc(3*4*sizeof(int)); D.p = (int*) malloc(3*4*sizeof(int)); 29. What will be output if you will compile and execute the following c code? void main() int i=320; char *ptr=(char *)&i; printf("%d",*ptr); A.320 B.1 C.64 D.Compiler error 30. What will be the output of the program?
char *s; char *fun(); s = fun(); printf("%s\n", s); char *fun() char buffer[30]; strcpy(buffer, "RAM"); return (buffer); A.0xffff B.Garbage value C.0xffee D.Error