1.
Void main()
{
int const * p=5;
printf("%d",++(*p));
}
Correct Answer
A. COMPILER ERROR
Explanation
The given code will result in a compiler error because it is attempting to modify the value of a constant variable. The variable 'p' is declared as a pointer to a constant integer using the 'const' keyword, and then it is assigned the value 5. However, when the code tries to increment the value pointed to by 'p' using the '++' operator, it is not allowed because 'p' is a pointer to a constant value. This violates the const-correctness rule and leads to a compiler error.
2.
Main()
{
char s[ ]="man";
int i;
for(i=0;s[ i ];i++)
printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}
Correct Answer
C. Mmmm
aaaa
nnnn
Explanation
The given code is a C program that prints a pattern based on the characters in the string "man". The for loop iterates through each character in the string. Inside the loop, the printf statement is used to print the characters in different ways.
In the first iteration of the loop, the characters 'm', 'a', and 'n' are printed using different methods: s[i], *(s+i), *(i+s), and i[s].
The output of the program will be "mmmm", "aaaa", and "nnnn" printed on separate lines. Therefore, the correct answer is "mmmm aaaa nnnn".
3.
6. main()
{
extern int i;
i=20;
printf("%d",i);
}
Correct Answer
A. LINKER ERROR
Explanation
The code is trying to access a variable "i" that is declared as extern, which means it is defined in another file. However, there is no definition or declaration of "i" in the current file. This leads to a linker error because the linker is unable to find the definition of "i" and link it with the code. Therefore, the correct answer is LINKER ERROR.
4.
Predict the output of the following C snippets
int main()
{
int main = 56;
printf("%d", main);
return 0;
}
Correct Answer
C. 56
Explanation
main is not a keyword in C.
5.
What is the output of this C code?
#include
int main()
{
float a = 3.14, *fptr;
fptr = &a;
printf("Size of Float Pointer : %d", sizeof(fptr));
return (0);
}
Correct Answer
D. Size of Float Pointer : 8
Explanation
The correct answer is "Size of Float Pointer : 8". In this code, a float variable "a" is declared and assigned a value of 3.14. Then, a float pointer "fptr" is declared and assigned the address of "a". The sizeof() function is used to determine the size of the float pointer "fptr", which is 8 bytes on most systems.
6.
What is the output of the below c code?
#include<stdio.h>
int main()
{
char ch;
if(ch = printf(""))
printf("It matters\n");
else
printf("It doesn't matters\n");
return 0;
}
Correct Answer
B. It doesn’t matters
Explanation
printf returns the number of characters successfully written on output.Hence ch=0 and else statement executes.
7.
Which one do you like?
int main()
{
fork();
fork();
printf("Hello world\n");
}
Correct Answer
C. 4
Explanation
fork is an operation wherein the process makes another copy of itself.
8.
What is the output of this C code?
void main()
{
int i, j;
for(i=0,j=0;i<10,j<20;i++,j++){
printf("i=%d \t j=%d\n", i, j);
}
}
Correct Answer
A. Print i and j till 19
Explanation
The code uses a comma operator in the condition of the for loop. The comma operator evaluates both expressions and returns the value of the second expression. In this case, the loop will continue as long as both i is less than 10 and j is less than 20. Since both variables are incremented in each iteration, they will eventually reach 19. Therefore, the code will print the values of i and j until they both reach 19.
9.
What is the output of this C code?
#include<stdio.h>
int main()
{
int x=1, y=0,z=5;
int a=x&&y||++z;
printf("%d",z++);
}
Correct Answer
C. 6
Explanation
and operator doesnt operate if second argument is zero. & operator has more precedence than ||
10.
What is the output of this C code?
#include<stdio.h>
int main()
{
int y = 2;
int z = y +(y = 10);
printf("%d\n", z);
}
Correct Answer
C. 20
Explanation
The output of this C code is 20. In the line "int z = y +(y = 10)", the value of y is first assigned as 10 and then added to itself, resulting in z being assigned a value of 20. The printf statement then prints the value of z, which is 20.