Which of the following is the correct syntax to declare a variable in C?
Answer: A
In C, variable declaration requires a semicolon at the end. The syntax is 'data_type variable_name;'
Q.2Easy
What does the following code snippet output?
#include <stdio.h>
int main() {
int x = 5;
printf("%d", x++);
return 0;
}
Answer: A
x++ is post-increment. The value 5 is printed first, then x is incremented to 6.
Q.3Medium
Which of the following is NOT a valid C keyword?
Answer: C
mutable is a C++ keyword, not a C keyword. extern, volatile, and register are valid C keywords.
Q.4Easy
What is the output of: printf("%d", 5 + 3 * 2)?
Answer: B
Following operator precedence, multiplication (*) has higher precedence than addition (+). So 3*2=6, then 5+6=11.
Q.5Medium
Which of the following is the correct way to define a constant in C?
Answer: C
Both #define and const can be used to define constants in C. #define is a preprocessor directive, while const is a type qualifier.
Advertisement
Q.6Easy
What is the purpose of the main() function in C?
Answer: C
The main() function is the entry point where program execution begins. Every C program must have a main() function.
Q.7Hard
What will be the output of: int x = 10; printf("%d %d", x, x++);
Answer: D
Modifying and using a variable in the same expression without an intervening sequence point results in undefined behavior.
Q.8Easy
Which escape sequence represents a tab character in C?
Answer: A
\t is the escape sequence for a tab character. \n is for newline, \s is invalid in C.
Q.9Medium
What is the return type of strlen() function?
Answer: C
strlen() returns size_t, which is an unsigned integer type used for sizes and counts.
Q.10Medium
Consider: void func(int *p); Which statement is correct about this function declaration?
Answer: B
The * in the parameter declaration indicates that func takes a pointer to an integer, not an integer value.
Q.11Medium
What will happen if we try to modify a const variable in C?
Answer: B
Attempting to modify a const variable results in a compilation error as const variables are read-only.
Q.12Medium
Which of the following correctly represents a character constant in C?
Answer: B
Character constants in C use single quotes ('A'). Double quotes ("") are for string literals. A single character in double quotes is a string, not a character constant.
Q.13Hard
Consider the expression: int arr[5]; What does arr represent without the index?
Answer: B
In C, the array name arr (without index) decays to a pointer to its first element, representing the base address.
Q.14Medium
What is the output of: printf("%f", 27);
Answer: B
27 performs integer division resulting in 3. Using %f format specifier prints it as 3.0 (or similar float representation).
Q.15Hard
Which storage class has a default value of 0 if not explicitly initialized?
Answer: C
Static variables are initialized to 0 by default. auto and register variables have garbage values if not initialized. extern variables are declared elsewhere.
Q.16Hard
What will be the output of the following code?
#include <stdio.h>
int main() {
int x = 5;
printf("%d", ++x + x++);
return 0;
}
Answer: D
The expression ++x + x++ involves modifying x multiple times without an intervening sequence point, leading to undefined behavior in C.
Q.17Medium
What is the size of the following structure in bytes (assuming 32-bit system)?
struct Point {
char c;
int x;
double d;
}
Answer: B
Due to structure padding and alignment: char (1 byte) + padding (3 bytes) + int (4 bytes) + double (8 bytes) = 16 bytes.
Q.18Medium
What will be printed by the following code?
#include <stdio.h>
int main() {
float f = 0.1 + 0.2;
if(f == 0.3)
printf("Equal");
else
printf("Not Equal");
return 0;
}
Answer: B
Due to floating-point precision limitations, 0.1 + 0.2 does not exactly equal 0.3 in binary representation.
Q.19Easy
Which keyword is used to create a variable that cannot be modified after initialization?
Answer: B
The 'const' keyword creates a constant variable that cannot be modified after initialization. The compiler enforces this at compile time.
Q.20Easy
What is the output of the following code?
#include <stdio.h>
int main() {
int arr[] = {10, 20, 30};
printf("%d", *(arr + 1));
return 0;
}
Answer: B
arr + 1 points to the second element. Dereferencing with * gives the value 20.