0
0
Cprogramming~10 mins

Using return codes - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to return success from main.

C
int main() {
    return [1];
}
Drag options to blanks, or click blank then click option'
AEXIT_SUCCESS
B1
C0
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 1 or -1 means an error occurred.
Using EXIT_SUCCESS requires including .
2fill in blank
medium

Complete 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'
A1
B0
CEXIT_FAILURE
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 0 means success, not error.
EXIT_FAILURE requires including .
3fill in blank
hard

Fix the error in the return statement to indicate failure.

C
int main() {
    return [1];
}
Drag options to blanks, or click blank then click option'
A2
B0
CEXIT_SUCCESS
DEXIT_FAILURE
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 0 means success, not failure.
Using numbers like 2 is less clear than EXIT_FAILURE.
4fill in blank
hard

Fill 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'
AEXIT_SUCCESS
BEXIT_FAILURE
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 and 1 directly without macros.
Returning success for negative values.
5fill in blank
hard

Fill 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'
AEXIT_SUCCESS
BEXIT_FAILURE
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 0 for failure cases.
Not handling default case properly.