Sonata Previous Years Solved Sample Placement Papers
-
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 Answer: Option D
-
If the following program (
myprog
) is run from the command line asmyprog friday tuesday sunday
, what would be the output?
main(int argc, char *argv[])
{
printf("%c", **++argv);
}A. m
B. f Answer: Option B
C. myprog
D. friday
-
If the following program (
myprog
) is run from the command line asmyprog friday tuesday sunday
, what would be the output?
main(int argc, char *argv[])
{
printf("%c", *++argv[1]);
}A. r Answer: Option A
B. f
C. m
D. y
-
If the following program (
myprog
) is run from the command line asmyprog 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 Answer: Option C
D. sunday tuesday friday
-
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.
-
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));
-
Would the following program compile?
main()
{
int a=10, *j;
void *k;
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 Answer: Option C
D. No, the arithmetic operation is not permitted on pointers
-
According to ANSI specifications, which is the correct way of declaring
main()
when it receives command line arguments?
A.
main(int argc, char *argv[])
Answer: Option AB.
main(argc, argv) int argc; char *argv[];
C.
main() {int argc; char *argv[]; }
D. None of the above
-
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
Answer: Option CD. None of the above
-
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.
-
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 Answer: Option A
B. 10
C. Error
D. Garbage value
-
A switch statement cannot include:
A. constants as arguments
B. constant expression as arguments
C. string as an argument Answer: Option C
D. None of the above
-
How long will the following program run?
main()
{
printf("\nSonata Software");
main();
}A. infinite loop
B. until the stack overflows Answer: Option B
C. All of the above
D. None of the above
-
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 Answer: Option C
D. None of the above
-
What is the output of the following program?
main()
{
int n = 5;
printf("\nn = %*d", n, n);
}A. n=5
B. n=5
C. n= 5 Answer: Option C
D. error