mutable is a C++ keyword, not a C keyword. extern, volatile, and register are valid C keywords.
Q.2Medium
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.
Q.3Medium
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.4Medium
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.5Medium
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.
Advertisement
Q.6Medium
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.7Medium
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.8Medium
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.9Medium
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.10Medium
What will be the output of the following code?
#include <stdio.h>
int main() {
int x = 10, y = 20;
int *p = &x, *q = &y;
*p = *q;
printf("%d %d", x, y);
return 0;
}
Answer: B
*p = *q assigns the value of y (20) to x through the pointer p. So x becomes 20, y remains 20.
Q.11Medium
What is the output of the following code?
#include <stdio.h>
int main() {
int a = 5, b = 10;
a = b++;
printf("%d %d", a, b);
return 0;
}
Answer: B
b++ returns the current value of b (10) before incrementing, so a = 10. Then b increments to 11.
Q.12Medium
Which of the following is NOT a valid data type modifier in C?
Answer: C
The 'long' modifier cannot be used with 'float'. You can only use 'double' or 'long double' for longer floating-point types.
Q.13Medium
Which memory segment stores global variables in C?
Answer: C
Global variables are stored in the data segment (also called BSS segment for uninitialized globals). Local variables use the stack.
Q.14Medium
In C, what is the purpose of the 'static' keyword when used with a global variable?
Answer: A
When 'static' is used with a global variable, it restricts its scope to the current file (internal linkage), making it not accessible from other files.
Q.15Medium
What is the range of values for 'signed char' in C (assuming 8-bit char)?
Answer: B
A signed char is 1 byte (8 bits) and can represent values from -128 to 127 using two's complement representation.
Q.16Medium
What will be the output of the expression: 25 in C (considering integer division)?
Answer: C
In C, when both operands are integers, division performs integer division, discarding the fractional part. 25 = 2.
Q.17Medium
Which of the following correctly represents a string literal in C?
Answer: B
Strings in C are represented using double quotes and stored in character arrays. Single quotes are for single characters.
Q.18Medium
What is the primary purpose of the 'volatile' keyword in C?
Answer: B
The 'volatile' keyword tells the compiler not to optimize accesses to a variable, as its value can change from external sources (hardware, signals, etc.).
Q.19Medium
What does the 'const' keyword do when applied to a pointer?
Answer: C
'const int *ptr' makes the data constant, 'int * const ptr' makes the pointer constant, and 'const int * const ptr' makes both constant.
Q.20Medium
Which of the following is a correct way to read a string from user input avoiding buffer overflow?
Answer: B
Using scanf("%10s", str) limits input to 10 characters, preventing buffer overflow. The gets() function is deprecated and unsafe.