1.
Main()
{
int a=3;
int *b=a;
printf(“%d”,b);
}
2.
Int main()
{
int n;
printf("Enter a number:\n");
scanf("%d\n",n);
printf("You entered %d \n",n);
return 0;
}
3.
Main()
{
int n;
scanf("%d",&n);
printf("%c",n);
}
4.
Main()
{
printf("!hello World);
}
5.
#include
int main()
{
printf("Value of a : %d",a);
return 0;
}
6.
Int Main()
{
printf("Hello : ");
return 0;
}
7.
Int Main()
{
printf("Hello : ");
return 0;
}
8.
Main()
{
int a=3;
int b=2;
int c=a
9.
Void main()
{
int a=4;
printf(“%d”,a);
return 0;
}
10.
Main()
{
int a=10;
printf(“%d”a);
}
11.
#include
int main()
{
float f1 = 0.1;
if (f1 == 0.1)
printf("equal\n");
else
printf("not equal\n");
}
Correct Answer
B. Not equal
Explanation
The reason why the answer is "not equal" is because floating-point numbers cannot be represented exactly in binary. The value 0.1 cannot be represented exactly in binary, so when it is assigned to the variable f1, it may not have the exact value of 0.1. Therefore, when comparing f1 to 0.1, they may not be equal.
12.
#include int main(){int x = 10000;double y = 56;int *p = &x;double *q = &y;printf("p and q are %d and %d", sizeof(p), sizeof(q));return 0;}
Correct Answer
A. P and q are 4 and 4
Explanation
The correct answer is "p and q are 4 and 4". The sizeof() function in C returns the size in bytes of its operand. In this case, p is a pointer to an integer and q is a pointer to a double. Both of these pointer types have a size of 4 bytes on most systems. Therefore, the sizeof(p) and sizeof(q) both evaluate to 4.
13.
#include
int main()
{
float x = 'a';
printf("%f", x);
return 0;
}
#include
int main()
{
float x = 'a';
printf("%f", x);
return 0;
}
Correct Answer
D. 97.000000
Explanation
The correct answer is 97.000000 because in the code, the variable "x" is assigned the value of 'a', which is the ASCII value of the character 'a'. Since "x" is a float data type, it will be implicitly converted to its corresponding ASCII value, which is 97. When the printf function is called with the format specifier "%f", it will print the value of "x" as a floating-point number, which is 97.000000.
14.
#include
void main()
{
int x = 0;
if (x == 0)
printf("hi");
else
printf("how are u");
printf("hello");
}
Correct Answer
D. Hihello
Explanation
The given code snippet is a C program that prints "hi", "how are u", and "hello" on separate lines. The variable x is initialized to 0 and the if statement checks if x is equal to 0. Since x is indeed equal to 0, the code inside the if block is executed, which prints "hi". The code outside the if block, which is the printf statement for "hello", is always executed regardless of the if condition. Therefore, the output of the program is "hi" followed by "hello".
15.
#include
void main()
{
int ch;
printf("enter a value btw 1 to 2:");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("1\n");
break;
printf("Hi");
default:
printf("2\n");
}
}
Correct Answer
D. 2
Explanation
The given code snippet is using a switch statement to check the value of the variable "ch". If the value is 1, it will print "1". However, after the break statement, there is a printf statement that will print "Hi". This statement is unreachable because the break statement will cause the control to exit the switch statement. Therefore, the code will only print "1".
16.
#include
void main()
{
int i = 0;
while (++i)
{
printf("H");
}
}
Correct Answer
B. H is printed infinte times
Explanation
The given code is an infinite loop because the condition of the while loop is always true. The variable "i" is incremented by 1 before each iteration of the loop. Since the value of "i" is initially 0, it becomes 1 in the first iteration, which satisfies the condition of the while loop. Therefore, the statement "H" is printed infinitely.
17.
#include
int main()
{
int a = 0, i = 0, b;
for (i = 0;i < 5; i++)
{
a++;
continue;
printf("%d",a);
}
printf("%d",a);
}
Correct Answer
A. 5
Explanation
In this code, a variable 'a' is initialized to 0. Then, a for loop is executed 5 times. In each iteration, the value of 'a' is incremented by 1 using the 'a++' statement. The 'continue' statement is used to skip the remaining code inside the loop and move to the next iteration. Therefore, the printf statement inside the loop is never executed. After the loop, the final value of 'a' is printed, which is 5.
18.
#include
void main()
{
int i = 0, j = 0;
for (i = 0;i < 5; i++)
{
for (j = 0;j < 4; j++)
{
if (i > 1)
break;
}
printf("Hi \n");
}
}
Correct Answer
A. Hi is printed 5 times
Explanation
The inner loop is never executed because the condition "i > 1" is never true. Therefore, the inner loop doesn't affect the number of times "Hi" is printed. The outer loop runs 5 times, so "Hi" is printed 5 times.
19.
#include
int main()
{
int i = 0, j = 0;
l1: while (i < 2)
{
i++;
while (j < 3)
{
printf("loop\n");
goto l1;
}
}
}
Correct Answer
A. Loop loop
Explanation
The code starts with initializing the variables i and j to 0. Then it enters a while loop with the condition i < 2. Inside this while loop, i is incremented by 1. Then it enters another while loop with the condition j < 3. Inside this while loop, "loop" is printed and then a goto statement is used to jump back to the label l1. This causes the code to repeat the previous while loop. Since j is never incremented, it remains 0 and the second while loop keeps getting executed infinitely. Therefore, the output will be "loop loop" repeatedly.
20.
#include
void main()
{
int i = 0;
int j = 0;
for (i = 0;i < 5; i++)
{
for (j = 0;j < 4; j++)
{
if (i > 1)
continue;
printf("Hi \n");
}
}
}
Correct Answer
B. Hi is printed 8 times
Explanation
The code contains nested for loops. The outer loop runs 5 times and the inner loop runs 4 times. However, there is a conditional statement inside the inner loop that uses the "continue" keyword. This means that if the value of "i" is greater than 1, the inner loop will skip the rest of its iterations and move to the next iteration of the outer loop. Therefore, when "i" is 2, 3, or 4, the inner loop is skipped entirely. As a result, "Hi" is only printed during the first two iterations of the outer loop, which gives a total of 8 times.