Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to return success from main.
C
int main() {
return [1];
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 1 or -1 means an error occurred.
Using EXIT_SUCCESS requires including .
✗ Incorrect
Returning 0 from main means the program ended successfully.
2fill in blank
mediumComplete the code to return an error code 1 from main.
C
int main() {
return [1];
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 0 means success, not error.
EXIT_FAILURE requires including .
✗ Incorrect
Returning 1 from main indicates an error occurred.
3fill in blank
hardFix the error in the return statement to indicate failure.
C
int main() {
return [1];
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 0 means success, not failure.
Using numbers like 2 is less clear than EXIT_FAILURE.
✗ Incorrect
Using EXIT_FAILURE clearly shows failure and is portable.
4fill in blank
hardFill both blanks to return success or failure based on condition.
C
int check(int value) {
if (value > 0) {
return [1];
} else {
return [2];
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 and 1 directly without macros.
Returning success for negative values.
✗ Incorrect
Return EXIT_SUCCESS for positive values and EXIT_FAILURE otherwise.
5fill in blank
hardFill all three blanks to return codes based on input.
C
int status(int code) {
switch(code) {
case 0:
return [1];
case 1:
return [2];
default:
return [3];
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 0 for failure cases.
Not handling default case properly.
✗ Incorrect
Return EXIT_SUCCESS for 0, EXIT_FAILURE for 1, and 1 for others.