In C, which of the following statements about pointers is TRUE?
Answer: B
A pointer stores the memory address of a variable. Pointer size depends on the system architecture, not always 4 bytes.
Q.22Medium
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.23Medium
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.24Medium
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.25Easy
What will be printed by the following code?
#include <stdio.h>
int main() {
char str[] = "Hello";
printf("%c", str[1]);
return 0;
}
What is the main difference between #define and const in C?
Answer: C
#define is a preprocessor directive replaced before compilation, while const creates an actual variable. const occupies memory; #define does not.
Q.27Hard
Which of the following correctly declares a function pointer?
Answer: B
Function pointers require parentheses around the pointer name: int (*func)(). Option D declares a function returning int pointer, not a function pointer.
Q.28Medium
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.29Easy
What is the output of the following code?
#include <stdio.h>
int main() {
char c = 'A';
printf("%d", c);
return 0;
}
Answer: A
The %d format specifier prints the ASCII value of the character. 'A' has ASCII value 65.
Q.30Hard
What will be the output of the following code?
#include <stdio.h>
int main() {
int x = 5;
int y = ++x * ++x;
printf("%d", y);
return 0;
}
Answer: C
The expression ++x * ++x modifies x twice without an intervening sequence point, causing undefined behavior.
Q.31Medium
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.32Easy
Which of the following is the correct syntax to declare a pointer to an integer in C?
Answer: A
In C, a pointer to an integer is declared using 'int *ptr;' where '*' indicates pointer declaration.
Q.33Easy
What is the size of 'char' data type in C?
Answer: C
The 'char' data type in C occupies 1 byte of memory and can store a single character.
Q.34Easy
Which of the following variable names is valid in C?
Answer: C
Variable names in C must start with a letter or underscore, followed by alphanumeric characters or underscores. '_variable123' is valid, while '2variable' starts with digit, 'var-iable' has hyphen, and 'var iable' has space.
Q.35Easy
What is the default return type of the main() function in C?
Answer: B
The main() function implicitly returns int type, which indicates the program's exit status (0 for success, non-zero for failure).
Q.36Easy
Which escape sequence is used to print a newline character in C?
Answer: B
The escape sequence \n represents a newline character that moves the cursor to the next line.
Q.37Medium
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.38Medium
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.39Medium
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.40Medium
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.).