Search Tutorials


C Decision Making and Loops MCQ Questions and Answers | JavaInUse

C Decision Making and Loops MCQ Questions and Answers

Q. What is the type of loop that is used when the number of iterations is unknown and continues until a certain condition is met?

A. for loop
B. while loop
C. do-while loop
D. none of the above

Q. Which loop is used when you want to iterate through a range of values and know the number of iterations beforehand?

A. for loop
B. while loop
C. do-while loop
D. none of the above

Q. How can you exit a loop prematurely if a certain condition is met?

A. using the continue statement
B. using the break statement
C. using the return statement
D. using the exit statement

Q. What is the purpose of the switch statement in C?

A. to perform arithmetic operations
B. to make decisions based on multiple choices
C. to repeat a block of code
D. to execute a block of code based on different cases

Q. What is the default case in a switch statement used for?

A. to handle arithmetic operations
B. to handle invalid input
C. to handle floating-point numbers
D. to execute code when no other case matches

Q. What is the purpose of the break statement in a switch case?

A. to exit the switch statement
B. to continue to the next case
C. to repeat the current case
D. to exit the current case and move to the next statement

Q. What is the purpose of the continue statement in a loop?

A. to exit the loop
B. to skip the rest of the current iteration and move to the next iteration
C. to repeat the current iteration
D. to start a new loop

Q. What is the purpose of the Predicate functional interface in Java 8?

A. To produce results
B. To consume values
C. To filter elements based on a condition
D. To transform values





Q. What is the purpose of the Function functional interface in Java 8?

A. To perform side effects
B. To consume values and produce results
C. To filter elements
D. To transform values

Q. What is the purpose of the Supplier functional interface in Java 8?

A. To consume values
B. To produce results
C. To filter elements
D. To create and supply values

Q. What is the purpose of the Consumer functional interface in Java 8?

A. To produce results
B. To consume values
C. To filter elements
D. To transform values

Q. What is the purpose of the if-else statement in C?

A. to repeat a block of code
B. to make decisions based on multiple choices
C. to execute a block of code based on a condition
D. to perform arithmetic operations

Q. What is the purpose of the else if statement in C?

A. to handle multiple conditions
B. to repeat a block of code
C. to make decisions based on multiple choices
D. to handle additional conditions after an if statement

Q. What is the purpose of the ternary operator (?:) in C?

A. to perform arithmetic operations
B. to handle multiple conditions
C. to provide a concise way to write if-else statements
D. to repeat a block of code

Q. What is the purpose of the do-while loop in C?

A. to repeat a block of code a specified number of times
B. to repeat a block of code until a condition becomes false
C. to repeat a block of code indefinitely
D. to make decisions based on multiple choices

Q. What will be the output of the following code snippet?

int num = 10;

if (num < 20) {
    printf("Num is less than 20");
} else {
    printf("Num is greater than or equal to 20");
}
A.
Num is less than 20
B.
Num is greater than or equal to 20
C.
Num is less than 10
D.
None of the above

Q. How can you rewrite the following if-else statement using the ternary operator?

int score = 85;

if (score >= 90) {
    printf("A");
} else {
    printf("B");
}
A.
printf(score >= 90 ? "A" : "B");
B.
printf(score < 90 ? "A" : "B");
C.
printf(score == 90 ? "A" : "B");
D.
None of the above

Q. What will be the output of the following code snippet?

int i = 1;

while (i <= 5) {
    printf("Count: %d\n", i);
    i++;
}
A.
Count: 1
Count: 2
Count: 3
Count: 4
Count: 5
B.
Count: 1
Count: 2
Count: 3
C.
Count: 1
Count: 1
Count: 1
Count: 1
Count: 1
D.
None of the above

Q. What will be the output of the following code snippet?

int i = 1;

do {
    printf("Count: %d\n", i);
    i++;
} while (i <= 5);
A.
Count: 1
Count: 2
Count: 3
Count: 4
Count: 5
B.
Count: 1
Count: 2
Count: 3
C.
Count: 1
Count: 1
Count: 1
Count: 1
Count: 1
D.
None of the above

Q. What will be the output of the following code snippet?

int i;

for (i = 1; i <= 5; i++) {
    printf("Count: %d\n", i);
}
A.
Count: 1
Count: 2
Count: 3
Count: 4
Count: 5
B.
Count: 1
Count: 2
Count: 3
C.
Count: 1
Count: 1
Count: 1
Count: 1
Count: 1
D.
None of the above

Q. What will be the output of the following code snippet?

int i, j;

for (i = 1; i <= 3; i++) {
    for (j = 1; j <= 2; j++) {
        printf("(%d, %d)\n", i, j);
    }
}
A.
(1, 1)
(1, 2)
(2, 1)
(2, 2)
(3, 1)
(3, 2)
B.
(1, 1)
(2, 1)
(3, 1)
C.
(1, 1)
(1, 2)
(2, 1)
(2, 2)
D.
(1, 1)
(2, 2)
(3, 3)

Q. What will be the output of the following code snippet?

int i = 1;

while (i <= 5) {
    if (i == 3) {
        break;
    }
    printf("Count: %d\n", i);
    i++;
}
A.
Count: 1
Count: 2
B.
Count: 1
Count: 2
Count: 3
Count: 4
Count: 5
C.
Count: 1
Count: 2
Count: 3
D.
None of the above

Q. What will be the output of the following code snippet?

int i = 1;

while (i <= 5) {
    if (i == 3) {
        continue;
    }
    printf("Count: %d\n", i);
    i++;
}
A.
Count: 1
Count: 2
Count: 4
Count: 5
B.
Count: 1
Count: 2
Count: 3
Count: 4
Count: 5
C.
Count: 3
D.
None of the above

Q. What will be the output of the following code snippet?

int i;

for (i = 1; i <= 5; i++) {
    if (i == 3) {
        break;
    }
    printf("Count: %d\n", i);
}
A.
Count: 1
Count: 2
B.
Count: 1
Count: 2
Count: 3
Count: 4
Count: 5
C.
Count: 1
Count: 2
Count: 3
D.
None of the above