1.
Print the elements of linked list in reverse order without using another linked list or data structures?
2.
#define square(x) x*x
void main()
{
int i;
i = 64/square(4);
printf("%d",i);
}
Correct Answer
B. 64
Explanation
The correct answer is 64 because the square macro is defined as x*x. In the main function, the expression 64/square(4) is evaluated. Since square(4) is expanded to 4*4, the expression becomes 64/16 which equals 4. Therefore, the value of i is 4. However, the printf statement is missing a semicolon at the end, so the code will not compile.
3.
Int fact(int N)
{
return (N * fact(N-1));
}
void main()
{
int N=5;
int factorial = fact(N);
printf(“%d”,factorial);
}
Correct Answer
B. Stack overflow
Explanation
The given code defines a recursive function called "fact" which calculates the factorial of a given number. In the main function, the variable N is assigned a value of 5, and then the fact function is called with N as the argument. The result of the factorial calculation is stored in the variable "factorial" and then printed using printf.
However, the code does not have a base case for the recursive function, which means it will keep calling itself indefinitely, causing a stack overflow error. This error occurs when the call stack, which keeps track of function calls, exceeds its maximum limit.
4.
What is the output of this statement ? (Question asked in Citrix)
printf(“%d”,printf(“%d%d”,2,2) & printf(“%d%d ”, 2, 2));
Correct Answer
A. 22222
Explanation
The printf function is used to print the output to the console. In this statement, there are three printf functions nested within each other. The innermost printf function ("%d%d", 2, 2) will print "22" to the console. The middle printf function ("%d%d", 2, 2) will also print "22" to the console. The outermost printf function ("%d", printf("%d%d", 2, 2) & printf("%d%d ", 2, 2)) will print the result of the bitwise AND operation between the return values of the two inner printf functions. Since both inner printf functions return 2, the bitwise AND operation will result in 2. Therefore, the output of the statement is "22222".
5.
#include<stdio.h>
int main()
{
int *p[10];
printf(“%d %d”,sizeof(p),sizeof(*p));
return 0;
}
Correct Answer
D. Depends on Compiler
Explanation
TRAP: all who have marked 40,4. Please note whenever there is an option for such questions as compiler dependent then plz mark that as the answer. For 64 bit compiler, answer is 80 8. For 32 bit compiler- 40 4
6.
If there is a large quantum in round robin scheduling method, it will be equivalent to
Correct Answer
A. First Come First Serve
Explanation
Question on Operating System, scheduling policies
7.
Which among the following scheduling policies will lead to starvation of processes?
Correct Answer
B. Shortest Job First
Explanation
Shortest Job First scheduling policy can lead to starvation of processes. This is because in this policy, the process with the shortest burst time is given the highest priority and is executed first. If there are long processes in the system, they may have to wait for a long time before getting a chance to execute, leading to starvation. This policy prioritizes short processes, neglecting the longer ones, which can result in unfairness and starvation.
8.
If there are 9 yellow balls, 3 red balls and 2 green balls. What is the probability that the second ball picked is yellow given the first ball is yellow ?
Correct Answer
A. 8/13
Explanation
The probability of picking a yellow ball as the second ball depends on the number of yellow balls remaining in the bag after the first yellow ball is picked. Since there are 9 yellow balls in total, and one is already picked, there are 8 yellow balls remaining. The total number of balls remaining in the bag is 13 (9 yellow + 3 red + 2 green). Therefore, the probability of picking a yellow ball as the second ball is 8/13.
9.
#include<stdio.h>
struct ABC
{
int a;
char b;
}abc;
int main()
{
printf("sizeof structure:%d",sizeof(abc));
return 0;
}
Correct Answer
C. 8
Explanation
V Important Question(Structure Padding)
10.
#include<stdio.h>
int main()
{
if(sizeof(int)>-1)
printf(“TRUE”);
else
printf(“FALSE”);
return 0;
}
Correct Answer
B. FALSE
Explanation
Only use unsigned types for modular arithmetic, bits manipulations (&, |, ^, , ~ operators), byte manipulations (unsigned char means "byte" in C/C++), and characters (unsigned char means character in C/C++).
11.
#include<stdio.h>
void main()
{
int a =10;
void *k;
k =&a;
k++;
printf(“%d”,k);
}
Correct Answer
A. Compiler Error
Explanation
Hint: its related to void pointer concept
12.
Void main()
{
static int a = 5;
printf(“%d”, a--);
if (a) main();
}
Correct Answer
A. 5 4 3 2 1
Explanation
The code starts by declaring a static integer variable "a" with a value of 5. It then prints the value of "a" (which is 5) and decrements it by 1. After that, it checks if "a" is still non-zero, and if it is, it calls the main function recursively. This process continues until "a" becomes 0. Therefore, the code will print the values of "a" in descending order: 5, 4, 3, 2, 1.
13.
Void main() (Assume int to be of 2 bytes)
{
unsigned int i= 3;
while(i-- >=0)
printf(“%u”,i);
}
Correct Answer
A. 3 2 1 0 65535 65534 …..3 2 1 0 ….
Explanation
The code snippet initializes the variable "i" with the value 3. The while loop is executed until "i" is greater than or equal to 0. In each iteration of the loop, the value of "i" is printed using the printf function. However, the condition in the while loop is i-- >= 0, which means that "i" is decremented before the comparison is made. Therefore, the loop will execute four times with the values 3, 2, 1, and 0 being printed. After the fourth iteration, "i" becomes -1, but since it is an unsigned int, it wraps around to the maximum value of an unsigned int (65535) and continues decrementing. This results in a sequence of decreasing values being printed until "i" reaches 0 again.