Sonata Previous Years Solved Sample Placement Papers
-
Point out the 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 parenthesis as follows: a>=5 ? b=100 : (b=200); -
In the following code, in which order would the functions be called?
a = f1(23,14)*f2(12/4)+f3();
- f1, f2, f3
- f3, f2, f1
- The order may vary from compiler to compiler
- 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 hair 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 mouse is an elephant built by the Japanese
- Breeding rabbits is a hare raising experience
- All of the above
- None of the above
-
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); }
- 25
- 11
- Error
- 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); }
- Line 1
- Line 5
- Line 6
- Line 7
-
What is the type of the variable
b
in the following declaration?#define FLOATPTR float* FLOATPTR a,b;
- float
- float pointer
- int
- int pointer
-
In the following code:
#include<stdio.h> main() { FILE *fp; fp = fopen(trial,r); }
- The first character in the file
- A structure which contains a char pointer which points to the first character in the file
- The name of the file
- None of the above
-
We should not read after a write to a file without an intervening call to
fflush()
,fseek()
, orrewind()
. Ans: True -
If the program
myprog
is run from the command line asmyprog 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]); }
- 1 2 3
- C:\MYPROG.EXE 1 2 3
- MYP
- None of the above
-
If the following program
myprog
is run from the command line asmyprog 1 2 3
, what would be the output?main(int argc, char *argv[]) { int i,j=0; for(i=0;i<argc;i++) j = j + atoi(argv[i]); printf(%d,j); }
- 1 2 3
- 6
- Error
- 123
-
If the following program
myprog
is run from the command line asmyprog monday tuesday wednesday thursday
, what would be the output?main(int argc, char *argv[]) { while(--argc > 0) printf(%s,*++argv); }
- myprog monday tuesday wednesday thursday
- monday tuesday wednesday thursday
- myprog tuesday thursday
- None of the above
-
In the following code, is
p2
an integer or an integer pointer?typedef int* ptr ptr p1,p2;
Ans: Integer pointer -
Point out the error in the following program:
main() { const int x; x = 128; printf(%d,x); }
Ans: x should have been initialized where it is declared. -
What would be the output of the following program?
main() { int y=128; const int x=y; printf(%d,x); }
- 128
- Garbage value
- Error
- 0