Sonata Previous Years Solved Sample Placement Papers
-
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 expressions like 1*2+4 are acceptable in cases of a switch.
-
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 parentheses as follows:
a >= 5 ? b = 100 : (b = 200);
-
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 Answer: Option C
D. None of the above
-
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 hare raising experience"); break; case 2: printf("\n Friction is a drag"); break; case 3: printf("\n If practice makes 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
D. None of the above Answer: Option D
-
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 Answer: Option A
B. 11
C. error
D. garbage value
-
In which line of the following, an error would be reported?
#define CIRCUM(R) (3.14 * R * R) main() { float r = 1.0, c; c = CIRCUM(r); printf("\n%f", c); if (CIRCUM(r) == 6.28) printf("\nGobbledygook"); }
A. line 1
B. line 5
C. line 6
D. line 7 Answer: Option D
-
What is the type of the variable b in the following declaration?
#define FLOATPTR float * FLOATPTR a, b;
A. float
B. float pointer Answer: Option B
C. int
D. int pointer
-
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. Answer: Option B
C. The name of the file.
D. None of the above.
-
We should not read after a write to a file without an intervening call to fflush(), fseek(), or rewind(). TRUE/FALSE
Ans. True
-
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; i < argc; i++) printf("%s", argv[i]); }
A. 1 2 3
B. C:\\MYPROG.EXE 1 2 3 Answer: Option B
C. MYP
D. None of the above