What will be the output of: int x = 5, y = 10; if (x < y) printf("yes"); else printf("no");
Answer: A
The condition x < y evaluates to true (5 < 10), so the if block executes, printing 'yes'. The else block is skipped.
Q.62Medium
Which of the following is NOT a valid way to pass arguments to a function in C?
Answer: B
C supports pass by value and pass by pointer/address. 'Pass by reference' as a concept exists in C++, not in C. In C, to achieve reference-like behavior, we use pointers.
Q.63Medium
What will be the result of: int a = 10, b = 3; int c = a % b; printf("%d", c);
Answer: B
The modulus operator % returns the remainder of division. 10 % 3 = 1 (since 10 = 3 × 3 + 1). Therefore, c = 1 and the output is 1.
Q.64Medium
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.
Q.65Medium
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.
Advertisement
Q.66Medium
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.67Medium
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.68Medium
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.69Medium
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.70Medium
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.71Medium
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.72Medium
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.73Medium
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.74Medium
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
Q.75Medium
What does the sizeof() operator return in C?
Answer: B
The sizeof() operator returns the size in bytes of a data type or variable. For example, sizeof(int) typically returns 4 on most 32-bit systems.
Q.76Medium
What does the modulus operator (%) return when applied to negative numbers?
Answer: B
In C, the modulus operator (%) returns a remainder that has the same sign as the dividend. For example, -7 % 3 = -1 (not 2), because -7 is the dividend and it's negative.
Q.77Medium
Which of the following statements about pointers is correct?
Answer: B
A pointer is a variable that stores the memory address of another variable. You can access the value at that address using the dereference operator (*), and pointers can point to any data type.
Q.78Medium
What is the correct way to declare a constant in C?
Answer: D
Both 'const int x = 10;' and 'int const x = 10;' are valid ways to declare a constant in C. The const keyword can be placed before or after the type specifier, and both have the same meaning.
Q.79Medium
How many times will the following loop execute: for(int i=0; i<5; i++) { if(i==3) break; }
Answer: B
The loop executes for i=0, i=1, and i=2. When i=3, the break statement is encountered, which immediately terminates the loop. Therefore, the loop executes exactly 3 times.
Q.80Medium
Which of the following is a correct way to initialize a pointer to NULL?
Answer: D
All three methods are correct ways to initialize a pointer to NULL. 0, NULL, and (void*)0 all represent a null pointer. NULL is typically a macro defined as 0 or ((void*)0) in the standard library.