Central Exam — Computer Knowledge
UPSC · SSC · Bank · Railway · NDA — Central Government Exam MCQ Practice
309 Questions 5 Topics Take Test
Advertisement
Showing 161–170 of 309 questions
Q.161 Easy C Programming
Which loop construct in C guarantees execution at least once?
A while loop
B for loop
C do-while loop
D nested loop
Correct Answer:  C. do-while loop
Explanation:

The do-while loop executes the body at least once before checking the condition. The syntax is: do { statements; } while(condition);. In contrast, while and for loops check the condition first.

Take Test
Q.162 Easy C Programming
What is the scope of a variable declared inside a block?
A Global scope
B Local scope (block scope)
C Static scope
D External scope
Correct Answer:  B. Local scope (block scope)
Explanation:

Variables declared inside a block (enclosed in curly braces) have local or block scope. They are accessible only within that block and cease to exist once the block execution is complete.

Take Test
Q.163 Medium C Programming
How many times will the following loop execute: for(int i=0; i
A 2 times
B 3 times
C 4 times
D 5 times
Correct Answer:  B. 3 times
Explanation:

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.

Take Test
Q.164 Medium C Programming
Which of the following is a correct way to initialize a pointer to NULL?
A int *ptr = 0;
B int *ptr = NULL;
C int *ptr = (void*)0;
D All of the above
Correct Answer:  D. All of the above
Explanation:

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.

Take Test
Q.165 Easy C Programming
What will be the value of x after executing: int x = 5; x += 3; x *= 2;
A 10
B 16
C 11
D 13
Correct Answer:  B. 16
Explanation:
Step 1: x = 5. Step 2: x += 3 means x = x + 3 = 5 + 3 = 8. Step 3: x *= 2 means x = x * 2 = 8 * 2 = 16. Therefore, x = 16.
Take Test
Advertisement
Q.166 Hard C Programming
Which of the following correctly describes the relationship between arrays and pointers in C?
A Arrays and pointers are identical
B An array name decays to a pointer to its first element
C Pointers can only be used with dynamically allocated arrays
D Arrays are pointers stored on the stack
Correct Answer:  B. An array name decays to a pointer to its first element
Explanation:

In C, when an array name is used in most contexts, it decays (converts) to a pointer to its first element. For example, in int arr[5];, arr behaves like &arr[0]. However, arrays and pointers are not identical; arrays have fixed size while pointers are variables.

Take Test
Q.167 Medium C Programming
What is the output of the expression: 10 / 3 * 3 in C?
A 10
B 9
C 3.33
D Cannot be determined
Correct Answer:  B. 9
Explanation:

Division and multiplication have the same precedence and are evaluated left-to-right. Step 1: 10 / 3 = 3 (integer division). Step 2: 3 * 3 = 9. Therefore, the result is 9.

Take Test
Q.168 Easy C Programming
Which preprocessor directive is used to include a custom header file?
A #include
B #include "filename"
C #include [filename]
D #include {filename}
Correct Answer:  B. #include "filename"
Explanation:

Custom/local header files are included using double quotes: #include "filename". Standard library headers use angle brackets: #include <filename>. The compiler searches for quoted files in the current directory first.

Take Test
Q.169 Hard C Programming
What is the difference between a function declaration and a function definition in C?
A Declaration provides the function signature; definition provides the implementation
B They are the same thing
C Declaration is optional; definition is mandatory
D Definition must appear before declaration
Correct Answer:  A. Declaration provides the function signature; definition provides the implementation
Explanation:

A function declaration (or prototype) tells the compiler about the function's name, return type, and parameters. A function definition includes the declaration along with the function body containing the actual implementation. Declaration is optional if the function is defined before use.

Take Test
Q.170 Hard C Programming
Which of the following is the correct way to declare a pointer to a function that returns an int and takes two int parameters?
A int *ptr(int, int);
B int (*ptr)(int, int);
C int *ptr[int, int];
D int ptr*(int, int);
Correct Answer:  B. int (*ptr)(int, int);
Explanation:

The correct syntax for a function pointer is: int (*ptr)(int, int);. The parentheses around (*ptr) are necessary to indicate that ptr is a pointer to a function, not a function returning a pointer. Option A declares a function returning an int pointer.

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