|
| 1 | +{ |
| 2 | + "id": "c-control-flow", |
| 3 | + "language": "c", |
| 4 | + "chapter": "control-flow", |
| 5 | + "title": "C Control Flow", |
| 6 | + "description": "Test your knowledge of C control flow statements including if-else, switch, loops, and decision making", |
| 7 | + "difficulty": "beginner", |
| 8 | + "estimatedTime": 15, |
| 9 | + "questions": [ |
| 10 | + { |
| 11 | + "id": 1, |
| 12 | + "question": "Which statement is used for decision making in C?", |
| 13 | + "options": [ |
| 14 | + "for", |
| 15 | + "while", |
| 16 | + "if", |
| 17 | + "goto" |
| 18 | + ], |
| 19 | + "correctAnswer": 2, |
| 20 | + "explanation": "The if statement is used for decision making by executing code based on a condition." |
| 21 | + }, |
| 22 | + { |
| 23 | + "id": 2, |
| 24 | + "question": "Which keyword is used to check multiple conditions in C?", |
| 25 | + "options": [ |
| 26 | + "if-else", |
| 27 | + "switch", |
| 28 | + "break", |
| 29 | + "continue" |
| 30 | + ], |
| 31 | + "correctAnswer": 1, |
| 32 | + "explanation": "The switch statement is used to select execution paths based on a variable value." |
| 33 | + }, |
| 34 | + { |
| 35 | + "id": 3, |
| 36 | + "question": "Which loop is guaranteed to execute at least once?", |
| 37 | + "options": [ |
| 38 | + "for", |
| 39 | + "while", |
| 40 | + "do-while", |
| 41 | + "nested loop" |
| 42 | + ], |
| 43 | + "correctAnswer": 2, |
| 44 | + "explanation": "The do-while loop executes its body at least once before checking the condition." |
| 45 | + }, |
| 46 | + { |
| 47 | + "id": 4, |
| 48 | + "question": "What is the correct syntax of an if statement?", |
| 49 | + "options": [ |
| 50 | + "if condition {}", |
| 51 | + "if (condition) {}", |
| 52 | + "if {condition}", |
| 53 | + "if [condition]" |
| 54 | + ], |
| 55 | + "correctAnswer": 1, |
| 56 | + "explanation": "In C, conditions in if statements must be written inside parentheses." |
| 57 | + }, |
| 58 | + { |
| 59 | + "id": 5, |
| 60 | + "question": "Which keyword is used to exit a loop immediately?", |
| 61 | + "options": [ |
| 62 | + "exit", |
| 63 | + "stop", |
| 64 | + "break", |
| 65 | + "return" |
| 66 | + ], |
| 67 | + "correctAnswer": 2, |
| 68 | + "explanation": "The break statement terminates the loop immediately." |
| 69 | + }, |
| 70 | + { |
| 71 | + "id": 6, |
| 72 | + "question": "Which loop is best suited when the number of iterations is known?", |
| 73 | + "options": [ |
| 74 | + "while", |
| 75 | + "do-while", |
| 76 | + "for", |
| 77 | + "switch" |
| 78 | + ], |
| 79 | + "correctAnswer": 2, |
| 80 | + "explanation": "The for loop is used when the number of iterations is known in advance." |
| 81 | + }, |
| 82 | + { |
| 83 | + "id": 7, |
| 84 | + "question": "What happens if the break statement is missing in a switch case?", |
| 85 | + "options": [ |
| 86 | + "Compilation error", |
| 87 | + "Program stops", |
| 88 | + "Execution continues to next case", |
| 89 | + "Switch ends immediately" |
| 90 | + ], |
| 91 | + "correctAnswer": 2, |
| 92 | + "explanation": "Without break, control falls through to the next case statement." |
| 93 | + }, |
| 94 | + { |
| 95 | + "id": 8, |
| 96 | + "question": "Which statement skips the current iteration of a loop?", |
| 97 | + "options": [ |
| 98 | + "break", |
| 99 | + "stop", |
| 100 | + "continue", |
| 101 | + "exit" |
| 102 | + ], |
| 103 | + "correctAnswer": 2, |
| 104 | + "explanation": "The continue statement skips the remaining code and moves to the next iteration." |
| 105 | + }, |
| 106 | + { |
| 107 | + "id": 9, |
| 108 | + "question": "Which operator is commonly used in decision-making conditions?", |
| 109 | + "options": [ |
| 110 | + "=", |
| 111 | + "==", |
| 112 | + ":=", |
| 113 | + "=>" |
| 114 | + ], |
| 115 | + "correctAnswer": 1, |
| 116 | + "explanation": "The '==' operator is used to compare two values in conditions." |
| 117 | + }, |
| 118 | + { |
| 119 | + "id": 10, |
| 120 | + "question": "Which statement is optional in a switch-case structure?", |
| 121 | + "options": [ |
| 122 | + "case", |
| 123 | + "break", |
| 124 | + "switch", |
| 125 | + "expression" |
| 126 | + ], |
| 127 | + "correctAnswer": 1, |
| 128 | + "explanation": "The break statement is optional, but without it, fall-through occurs." |
| 129 | + } |
| 130 | + ] |
| 131 | +} |
0 commit comments