Consider: int *ptr = NULL; *ptr = 5; What will happen?
Answer: B
Attempting to dereference a NULL pointer causes undefined behavior, typically resulting in a segmentation fault (runtime error). A NULL pointer doesn't point to valid memory.
Q.122Easy
Which of the following is a correct way to declare a pointer to an integer in C?
Answer: B
The correct syntax for declaring a pointer to an integer is 'int *ptr;' where the asterisk (*) indicates it is a pointer variable.
Q.123Easy
What is the output of the following code: printf("%d", sizeof(int));
Answer: C
sizeof(int) returns the size of integer in bytes as an integer value. On most modern systems, this is 4 bytes, and printf with %d will print this numeric value.
Q.124Easy
Which of the following correctly initializes a 2D array in C?
Answer: C
Both syntaxes are valid in C. Option A explicitly specifies both dimensions, while Option B lets the compiler calculate the first dimension based on initialization.
Q.125Medium
What will be the output of: char ch = 'A'; printf("%d", ch);
Answer: B
When a character is printed using %d format specifier, its ASCII value is printed. The ASCII value of 'A' is 65.
Advertisement
Q.126Easy
Which of the following is NOT a valid identifier in C?
Answer: B
In C, an identifier cannot start with a digit. It must start with a letter (a-z, A-Z) or underscore (_). Option B violates this rule by starting with a digit.
Q.127Medium
What is the output of: int x = 5; int y = ++x + x++; printf("%d %d", x, y);
Answer: A
Step 1: x=5. Step 2: ++x makes x=6 (pre-increment, used immediately). Step 3: y = 6 + x++ = 6 + 6 = 12. Step 4: x++ increments x to 7 after use. Final: x=7, y=12.
Q.128Easy
In C, what is the difference between single quotes and double quotes?
Answer: B
In C, single quotes (') are used for single character constants (char type), while double quotes (") are used for string literals (array of characters ending with null terminator).
Q.129Medium
What is the output of: int a = 10, b = 20; a = a ^ b; b = a ^ b; a = a ^ b; printf("%d %d", a, b);
Answer: B
This is XOR swap algorithm. Step 1: a = 10^20. Step 2: b = (10^20)^20 = 10. Step 3: a = (10^20)^10 = 20. Result: a=20, b=10 (values are swapped).
Q.130Medium
In C, which function is used to read a string from input with space handling?
Answer: B
fgets() is the safe way to read strings including spaces. scanf("%s") stops at whitespace, gets() is deprecated and unsafe due to buffer overflow risks.
Q.131Medium
What is the purpose of the 'static' keyword when used with a variable inside a function?
Answer: B
A static variable inside a function is initialized only once and retains its value between successive function calls. It has memory allocated in the data segment, not the stack.
Q.132Medium
Which of the following correctly represents a structure declaration in C?
Answer: C
Both are valid syntax. Option A declares an anonymous structure with immediate variable instantiation. Option B declares a named structure type that can be used later to create variables.
Q.133Hard
What does the 'volatile' keyword indicate in C?
Answer: A
The volatile keyword tells the compiler that a variable's value may change unexpectedly (e.g., due to hardware, interrupts, or other threads), preventing compiler optimizations that assume the value doesn't change.
Q.134Hard
Consider: int *ptr; int arr[] = {1,2,3}; ptr = arr; What is ptr[1]?
Answer: B
When ptr points to the array arr, ptr[1] is equivalent to *(ptr+1), which accesses the second element of the array, which is 2.
Q.135Medium
Which of the following operators has the highest precedence in C?
Answer: B
The increment (++) and decrement (--) operators have the highest precedence among all operators in C, followed by unary operators, then multiplicative, additive, and so on.
Q.136Easy
Which of the following is true about the 'break' statement in C?
Answer: B
The 'break' statement is used to exit or terminate a loop or switch statement immediately. It transfers control to the statement following the loop or switch.
Q.137Medium
What will be printed: int i = 0; while(i < 3) { printf("%d ", i); i++; }
Answer: A
The while loop starts with i=0. It prints 0, then increments i to 1, prints 1, increments to 2, prints 2, increments to 3, and the condition i<3 becomes false, so the loop terminates. Output: 0 1 2
Q.138Medium
What is the correct syntax to free dynamically allocated memory in C?
Answer: B
The free() function is used to deallocate memory that was previously allocated using malloc(), calloc(), or realloc(). This prevents memory leaks.
Q.139Medium
What does the following code do: int *ptr = NULL;
Answer: B
This declaration creates a pointer to an integer and initializes it to NULL, which means it doesn't point to any valid memory address. This is a safe initialization practice.
Q.140Medium
What is the output of: printf("%f", 25);
Answer: B
Since both 5 and 2 are integers, integer division is performed: 25 = 2. The %f format specifier then prints this integer value (2) as a floating-point number: 2.000000