Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'jump' instead of 'goto'.
Using 'break' or 'continue' outside loops.
✗ Incorrect
The goto statement is used to jump to a labeled statement in C.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the colon after the label name.
Adding a semicolon after the label.
✗ Incorrect
Labels in C end with a colon, like end:.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Adding a colon after the label name in goto.
Using incorrect punctuation.
✗ Incorrect
The correct syntax for goto is goto label_name; with a semicolon after the statement.
4fill in blank
hardComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the colon after the label.
Using incorrect syntax for goto.
✗ Incorrect
The label must end with a colon, and the goto statement jumps to that label.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using label names without colons.
Using incorrect label names.
✗ Incorrect
Use goto end; to jump to the label end:. The label start: is unused here.