Get in here to get the Interview Tips of Various Companies. Or see how to improve performances related to your job.

Test Paper :3
Paper Type : Whole Testpaper
Posted By : Nishant

QUARK Placement Sample Question Paper

C - Question Paper
Note : There are 20 questions and no negative marking.
Time allotted is 30 minutes

1. What is the output of the following code
main()
{
printf("Hello %d",printf("QUARK test? "));
}
a. Compile time error.
b. Hello QUARK test?
c. Run time error.
d. None of the above.
e. Quark Test ?Hello.

Ans. d.
This is because the evaluation of the parameters in a function call is done from right to left, becz the parameters were passed via a stack hence the first parameter (the leftmost one) is at the bottom of the stack and the rightmost parameter (if it is an expresseion, it will be evaluated before putting it on the stack) is on the top of the stack, hence while popping the parameters from the stack, the function printf (or any other function) gets them in the reverse order, i.e., from right to left, hence the statement printf( "Quark test? ") gets evaluated first while pushing it as a parameter on to the stack, and then the statement printf( "Hello %d') is executed. The '12' is the result of the return of printf( "Quark test? ") which returns the number of characters printed.

2.) Out put of the following code is
main()
{
int i,j,A;
for (A = -1;A<1>>1, x<<3);
}
a. 1 and 4
b. 1 and 24
c. 1 and 27
d. None of the above

Ans. 1 and 24
This is because 3 in binary is 00000000 00000011 in two bytes (integer). Again, the right to left evaluation rule of parameters is applicable and so x<<3>>1, right shift 1, 00000000 00000011, which is 1 in decimal, so 1 is pushed onto the stack, then printf("%dt %d") gets executed displaying 1 24.

9. What will be the result of the following code?

int *x;
x =(int *) 15;
a. Compilation error
b. Compiles but gives a runtime error
c. Absolute location 15 in the memory space shall be assigned to pointer x;
d. Location 15 in the program space is assigned to pointer x;
e. Location 15 contains the address to an integer.

Ans d


10. Which of the following functions cannot be called from another file?

a. const void func(){ ..}
b. extern void func(){ }
c. void func(){ }
d. static void func(){ .}

Ans. static

11. What will be the out come of the following code?

#include<stdio>

int * func(){
static int x=0;
x++; return &x;
}
int main()
{
int * y = func();
printf("%d",(*y)++);
func();
printf("%dn",*y);
return 0;
}

a. Compilation error.
b. Prints 1 and 3
c. Prints 1 and 3 but it is not good practice.
d. Prints 1 and 1
e. The code will not execute properly because y points to a variable whose life span is limited to execution of the function func();

Ans. Prints 1 and 3 but it is not a good practice

12. Referring to the above code , which of the following would be the correct
implementation for myFunc ?
char *format = "%d';
int main()
{
int x;
myFunc(scanf,&x);
printf( "%dn',x);
return(0);
}

a. void myFunc(int(*y)(const char*, ),int *x) {(*y)(format,&x);}
b. void myFunc(int(*y)(const char*, ),int *x) {(*y)(format,*x);}
c. void myFunc(int*y(const char*, ),int *x) {(*y)(format,&x);}
d. void myFunc(*(int y(const char*, )),int *x) {(*y)(format,x);}
e. void myFunc(int(*y)(const char*, ),int *x) {(*y)(format,x);}

13. What shall be the output of the following C code?
void main()
{
unsigned int x= -1;
int y =0;
if(y<x>=y) printf( "C is truen');
}
a. A is true.
b. B is true.
c. C is true.
d. None of the above.
Ans. A is true because x contains -1, i.e., in binary it is ffff, i.e., all 1s, so being unsigned, all 1s are interpreted as the value 65535 and not as -1 (however, all 1s are interpreted as -1 if it is just an int), hence y<x>=95)
return(q);
else
return(p);
}
a. 11
b. 29
c. Compilation error
d. Runtime error
e. None of the above.
Ans. e. None of the above. the statement c = check(11,29) is assigning an int ptr to an int, so c has an address of an int (which has gone out of scope, since the function returns the address of a variable which had its scope only inside the function, since the parameters were passed by value) so the value printed can be anything. Instead, if the statement was c = *(check(11,29)) then c would have the value stored at the address returned by the function, which would most probably be 11, but it cannot be guaranteed since the variable i has fallen out of scope.


18. What shall be the output of the following code?

void main()
{int a[3][2]={ 1,2,
5,7,
6,8};

printf("n%d",((a+1)-(&a+1)));
}
a. 0
b. -16
c. -2
d. -8
e. None of the above.

Ans. -2. I haven't been able to figure this one out. a is the address of the 2-d array, here a, &a, *a all give the same value, i.e., address of the array. (a+1) gives the address of the second row, it is the same as a[1]. *(a+1) gives the address of the first cell of the second row. **(a+1) gives the value of the element stored in the first cell in the second row. (*(a+1)+1) gives the address of the second cell of the second row. *(*(a+1)+1) gives the value of the element stored in the second cell in the second row.

19.What shall be the output of the following code?
main()
{
char str1[]="Hello";
char str2[]="Hello";
if(str1= =str2&& (*(str1+6)= =*(str2+6)))
printf("n Equal");
else
printf("n unequal");
}
a. Equal
b. Unequal
c. Compilation error.
d. Runtime error.
e. None of the above.

Ans. b. Unequal, because the addresses of the two strings are str1 and str2 and they are different.

20. Given that sizeof(int) is 2 , what is the output of the following code
main()
{
int a, b=255,c=127;
a=~b;
c=c^(~a & b|0);
c=c^(~(~b));
printf("%dn",c);
}
a. Error because of overflow;
b. 255
c. -256
d. 127
e. None of the above
Ans. d. 127
ADVERTISEMENT