1.
Pick up the right alternative
void main()
{
int const * p=5;
printf("%d",++(*p));
}
Correct Answer
C. Compiler Error
Explanation
The given code will result in a compiler error because it is trying to modify a constant value. The variable 'p' is declared as a pointer to a constant integer, and then it is assigned the value 5. However, the code then tries to increment the value pointed to by 'p' using the '++' operator, which is not allowed for constant variables. Therefore, the code will not compile successfully.
2.
Pick up the right alternative
main()
{
extern int i;
i=20;
printf("%d",i);
}
Correct Answer
D. Linker Error
Explanation
The given code snippet declares an external variable 'i' without defining it. When the variable 'i' is assigned the value 20, the linker is unable to find the definition of 'i' in any other file. Therefore, a linker error occurs.
3.
Pick up the right alternative
main()
{
char string[]="Hello World";
display(string);
}
void display(char *string)
{
printf("%s",string);
}
Correct Answer
A. Compiler Error
Explanation
The code will give a compiler error because the function display is called before it is declared. In C, functions need to be declared before they are used. To fix this error, the display function should be declared before the main function.
4.
Pick up the right alternative
main()
{
clrscr();
}
clrscr();
Correct Answer
C. No Output
Explanation
The given code is a simple C program that includes a main function. The function clrscr() is called twice in the code, once before the main function and once after it. However, the clrscr() function does not exist in the standard C library. Therefore, the compiler will throw an error stating that the clrscr() function is undefined. As a result, the code will not compile and there will be no output.
5.
Pick up the right alternative
main()
{
int x=5,y;
x=y;
printf(ā%d %dā, x, y);
}
Correct Answer
B. Garbage Value
Explanation
In this code, the variable y is not initialized before it is assigned to x. Therefore, the value of y is undefined or garbage. When the values of x and y are printed, the value of x will be garbage as it is assigned the garbage value of y. The value of y will also be garbage since it was never assigned a value. Hence, the correct answer is Garbage Value.
6.
Pick up the right alternative
#include
void main()
{
int x=5,*y;
x=y;
printf("%d %d",*x,*y);
}
Correct Answer
A. Compiler Error
Explanation
The code is attempting to assign the value of the pointer variable 'y' to the integer variable 'x', which is not allowed as they are of different types. This results in a compiler error.
7.
Pick up the right alternative
void main()
{
float *x=0.5;
int *y;
y=x;
printf("%d",*y);
}
Correct Answer
A. Compiler Error
Explanation
The given code will result in a compiler error. This is because the variable "x" is declared as a float pointer but it is assigned a float value directly, without using the address-of operator. This will cause a type mismatch error.
8.
Pick up the right alternative
#include
void main()
{
char *str="abcdef";
int n=str;
printf("%d",n);
}
Correct Answer
C. Warning
Explanation
The code is attempting to assign a character string to an integer variable, which can cause a warning. This is because the address of the string is being assigned to the integer variable, which may lead to unexpected behavior or errors.
9.
Pick up the right alternative
void main()
{
int n;
n=scanf("%d",&n)+printf("%d",n);
print("%d",n);
}
Correct Answer
D. Linker error
Explanation
In the given code, there is a mistake in the print statement. The correct function to print in C is "printf", not "print". This mistake will result in a linker error because the compiler will not be able to find the function "print" and link it with the code.
10.
Pick up the right alternative
void main()
{
int *x=10,*y='a';
char *p=97;
if(*p==*y)
printf("%d",*x);
}
Correct Answer
C. No Output
Explanation
The code will not produce any output because it contains several errors. The variables x, y, and p are declared as pointers but are assigned integer and character values directly instead of memory addresses. This will result in a compiler error. Additionally, the comparison *p==*y is comparing the values pointed to by p and y, which are both character values. Since the values 'a' and 97 are not equal, the condition will evaluate to false and the printf statement will not be executed. Therefore, there will be no output.