0
0
Cprogramming~10 mins

Goto statement overview in C - Interactive Code Practice

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

Complete the code to jump to the label using goto.

C
int main() {
    int x = 0;
    if (x == 0) {
        [1] skip;
    }
    printf("This will be skipped.\n");
    skip:
    printf("Jumped to label.\n");
    return 0;
}
Drag options to blanks, or click blank then click option'
Acontinue
Bjump
Cbreak
Dgoto
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'jump' instead of 'goto'.
Using 'break' or 'continue' outside loops.
2fill in blank
medium

Complete the code to define a label named 'end'.

C
int main() {
    int i = 5;
    if (i > 0) {
        printf("i is positive\n");
    }
    [1]
    return 0;
}
Drag options to blanks, or click blank then click option'
Aend:
Bend;
Cend
Dlabel
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the colon after the label name.
Adding a semicolon after the label.
3fill in blank
hard

Fix the error in the goto statement to jump to label 'start'.

C
int main() {
    [1];
    printf("At start label\n");
    return 0;
    start:
    printf("This is the start label.\n");
}
Drag options to blanks, or click blank then click option'
Agoto start
Bgoto start;
Cgoto start:
Dgoto; start
Attempts:
3 left
💡 Hint
Common Mistakes
Adding a colon after the label name in goto.
Using incorrect punctuation.
4fill in blank
hard

Complete the code to create a loop using goto and label.

C
int main() {
    int count = 0;
    loop_start:
    if (count < 3) {
        printf("Count: %d\n", count);
        count++;
        [1] loop_start;
    }
    return 0;
}
Drag options to blanks, or click blank then click option'
A:
Bgoto
C;
D,
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the colon after the label.
Using incorrect syntax for goto.
5fill in blank
hard

Fill all three blanks to use goto to skip printing 'Skipped' and jump to 'end' label.

C
int main() {
    int x = 1;
    if (x == 1) [1] end;
    printf("Skipped\n");
    [2]:
    printf("After label\n");
    return 0;
    [3]:
}
Drag options to blanks, or click blank then click option'
Agoto
Bend
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using label names without colons.
Using incorrect label names.