Computer Knowledge — C Programming
Aptitude · Reasoning · English · CS — Corporate & Campus Interview Prep
200 Questions 5 Topics Take Test
Advertisement
Showing 181–190 of 200 questions in C Programming
Q.181 Medium C Programming
Which loop construct will execute at least once even if the condition is false?
A while loop
B for loop
C do-while loop
D All of the above
Correct Answer:  C. do-while loop
Explanation:

The do-while loop executes the body first and then checks the condition, ensuring at least one execution. while and for loops check the condition first.

Take Test
Q.182 Medium C Programming
How is a two-dimensional array typically stored in memory in C?
A Column-major order
B Random order
C Row-major order
D Scattered order
Correct Answer:  C. Row-major order
Explanation:

C uses row-major order to store 2D arrays in memory. The elements are stored row by row sequentially in memory.

Take Test
Q.183 Hard C Programming
What is the difference between #include and #include "stdio.h"?
A They are identical
B searches in system directories, "" searches in current directory first
C "" is for user-defined headers, is for system headers
D Both B and C are correct
Correct Answer:  D. Both B and C are correct
Explanation:

Using <> tells the compiler to search in standard system directories. Using "" tells it to search in the current directory first, then system directories. Generally, "" is used for user-defined headers and <> for standard library headers.

Take Test
Q.184 Hard C Programming
Consider the code: int *p; int arr[5]; p = arr; What does p[2] represent?
A The address of arr[2]
B The value at arr[2]
C The pointer itself
D A syntax error
Correct Answer:  B. The value at arr[2]
Explanation:

When p points to arr, p[2] is equivalent to *(p+2) and accesses the value at arr[2]. Pointers and array names decay to pointers, and pointer indexing retrieves the value.

Take Test
Q.185 Hard C Programming
Which of the following will correctly allocate memory for an array of 10 integers?
A int *arr = malloc(10);
B int *arr = malloc(10 * sizeof(int));
C int arr[10] = malloc(10);
D int *arr = calloc(10);
Correct Answer:  B. int *arr = malloc(10 * sizeof(int));
Explanation:

malloc() allocates memory in bytes. To allocate for 10 integers, we need 10 * sizeof(int) bytes. Option A allocates only 10 bytes, insufficient for 10 integers.

Take Test
Advertisement
Q.186 Hard C Programming
What will be the output of: int x = 5; int y = x++ + ++x; ?
A y = 11
B y = 12
C y = 10
D Undefined behavior
Correct Answer:  D. Undefined behavior
Explanation:

This expression involves modifying the same variable (x) multiple times without an intervening sequence point. This is undefined behavior in C, and the result cannot be predicted reliably.

Take Test
Q.187 Easy C Programming
Which function is used to read a single character from standard input?
A scanf()
B getchar()
C gets()
D fgetc()
Correct Answer:  B. getchar()
Explanation:

getchar() reads a single character from standard input (stdin). While fgetc() can also read a character, getchar() is the standard dedicated function for this purpose.

Take Test
Q.188 Easy C Programming
In the expression: int arr[3][3]; arr[1][2] = 5; What is being accessed?
A Element in row 1, column 2
B Element in row 2, column 3
C Element in row 2, column 1
D Invalid access - syntax error
Correct Answer:  A. Element in row 1, column 2
Explanation:

In C, array indices are 0-based. arr[1][2] refers to the element in the second row (index 1) and third column (index 2) of the 2D array.

Take Test
Q.189 Easy C Programming
What is the output of the following C code?
int main() {
int a = 10;
printf("%d", a += 5);
return 0;
}
A 10
B 15
C 5
D Compilation Error
Correct Answer:  B. 15
Explanation:

The += operator adds 5 to a (a = a + 5 = 10 + 5 = 15), and printf prints the updated value 15.

Take Test
Q.190 Medium C Programming
What is the output of the following code?
int x = 5;
int y = ++x;
printf("%d %d", x, y);
A 5 5
B 6 6
C 6 5
D 5 6
Correct Answer:  B. 6 6
Explanation:

++x is pre-increment, which increments x before assignment. So x becomes 6, then y is assigned 6. Both x and y are 6.

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