VIRTUSA Previous Years Solved Sample Placement Papers
-
What is the difference between the following declarations?
const char *s;
char const *s;
Ans. No difference
-
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
-
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
-
Solution: The variable
a
is redeclared within the same scope, which is not allowed. -
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
B. 10
C. Error
D. Garbage value Answer: Option A
-
Solution: Attempting to modify a constant variable through a pointer will not change its value in most compilers, but it is undefined behavior. The program prints the original value of
x
, which is 5. -
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
- Solution: A switch statement only accepts constants or constant expressions as arguments; strings are not valid.
-
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
- Solution: The function calls itself recursively without any termination condition, leading to stack overflow eventually.
-
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
- Solution: Both forms are valid ways of allocating memory for a char pointer.
-
What is the output of the following program?
main()
{
int n=5;
printf("\nn=%*d",n,n);
}A. n=5
B. n= 5 Answer: Option B
C. n=5
D. error
-
Solution: The
%*d
format specifier dynamically sets the field width, which in this case is the value ofn
. -
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
-
In how many different ways can the letters of the word 'DETAIL' be arranged in such a way that the vowels occupy only the odd positions?
A. 32
B. 48
C. 36 Ans: C
D. 60
E. 120
-
What is the ratio of the peak ripple voltage level to its rms voltage level?
v3 Ans: A
v2
v3/2
v2/2
-
In an improved shunt regulator, which of the following components sets the reference voltage?
A. Transistor Q1
B. Zener diode Ans: B
C. Transistor Q2
D. RS