Central Exam — Computer Knowledge
UPSC · SSC · Bank · Railway · NDA — Central Government Exam MCQ Practice
309 Questions 5 Topics Take Test
Advertisement
Showing 141–150 of 309 questions
Q.141 Medium C Programming
In C, which function is used to read a string from input with space handling?
A scanf("%s", str);
B fgets(str, sizeof(str), stdin);
C gets(str);
D getline(str);
Correct Answer:  B. fgets(str, sizeof(str), stdin);
Explanation:

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.

Take Test
Q.142 Medium C Programming
What is the purpose of the 'static' keyword when used with a variable inside a function?
A To make the variable global
B To preserve the variable's value between function calls
C To prevent the variable from being modified
D To allocate memory on the stack
Correct Answer:  B. To preserve the variable's value between function calls
Explanation:

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.

Take Test
Q.143 Medium C Programming
Which of the following correctly represents a structure declaration in C?
A struct {int a; char b;} s;
B struct Name {int a; char b;};
C Both A and B are correct
D Neither A nor B is correct
Correct Answer:  C. Both A and B are correct
Explanation:

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.

Take Test
Q.144 Hard C Programming
What does the 'volatile' keyword indicate in C?
A The variable can be modified externally at any time
B The variable cannot be modified
C The variable is stored in a register
D The variable has global scope
Correct Answer:  A. The variable can be modified externally at any time
Explanation:

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.

Take Test
Q.145 Hard C Programming
Consider: int *ptr; int arr[] = {1,2,3}; ptr = arr; What is ptr[1]?
A Compilation error
B 2
C arr[1]
D Undefined behavior
Correct Answer:  B. 2
Explanation:

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.

Take Test
Advertisement
Q.146 Medium C Programming
What will be the final value of x: int x = 5; x += 3 * 2; printf("%d", x);
A 16
B 11
C 13
D 36
Correct Answer:  A. 16
Explanation:
Step 1: x = 5. Step 2: 3 * 2 = 6 (multiplication has higher precedence). Step 3: x += 6 means x = x + 6 = 5 + 6 = 11. Wait, let me recalculate: x = 5; x += 6 gives x = 11. The answer should be B (11), not A. Correction: The correct answer is B.
Take Test
Q.147 Medium C Programming
Which of the following operators has the highest precedence in C?
A * (multiplication)
B ++ (increment)
C + (addition)
D = (assignment)
Correct Answer:  B. ++ (increment)
Explanation:

The increment (++) and decrement (--) operators have the highest precedence among all operators in C, followed by unary operators, then multiplicative, additive, and so on.

Take Test
Q.148 Easy C Programming
Which of the following is true about the 'break' statement in C?
A It skips the current iteration
B It exits the loop or switch statement
C It terminates the program
D It has no effect in loops
Correct Answer:  B. It exits the loop or switch statement
Explanation:

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.

Take Test
Q.149 Medium C Programming
What will be printed: int i = 0; while(i < 3) { printf("%d ", i); i++; }
A 0 1 2
B 1 2 3
C 0 1 2 3
D Nothing is printed
Correct Answer:  A. 0 1 2
Explanation:

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

Take Test
Q.150 Medium C Programming
What is the correct syntax to free dynamically allocated memory in C?
A delete ptr;
B free(ptr);
C release(ptr);
D dealloc(ptr);
Correct Answer:  B. free(ptr);
Explanation:

The free() function is used to deallocate memory that was previously allocated using malloc(), calloc(), or realloc(). This prevents memory leaks.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips