Recall & Review
beginner
What is the
goto statement in C?The
goto statement in C is a way to jump directly to another part of the program marked by a label. It helps to change the flow of execution.Click to reveal answer
beginner
How do you define a label for
goto in C?A label is defined by writing an identifier followed by a colon, like
label_name:. The goto statement can jump to this label.Click to reveal answer
intermediate
Why should
goto be used carefully?Using
goto too much can make code hard to read and follow, like a messy map. It can cause bugs and confusion, so it is usually better to use loops and functions.Click to reveal answer
beginner
Can
goto jump outside a function in C?No,
goto can only jump to labels within the same function. It cannot jump between different functions.Click to reveal answer
beginner
Example: What does this code do?
int x = 0;
goto skip;
x = 5;
skip:
printf("%d", x);The code jumps over
x = 5; and prints 0 because the goto skip; moves execution directly to the label skip:.Click to reveal answer
What does the
goto statement do in C?✗ Incorrect
The
goto statement jumps to a label inside the same function.How do you mark a place to jump to with
goto?✗ Incorrect
Labels are identifiers followed by a colon, like
label:.Can
goto jump to a label in another function?✗ Incorrect
goto works only inside the same function.What is a common problem with using
goto too much?✗ Incorrect
Excessive use of
goto can make code confusing and messy.Which of these is a correct label for
goto?✗ Incorrect
Labels are written as an identifier followed by a colon, like
start:.Explain how the
goto statement works and when it should be used.Think about how <code>goto</code> changes program flow and why it can be risky.
You got /4 concepts.
Describe a simple example where
goto skips a part of the code.Imagine skipping a step in a recipe using a shortcut.
You got /4 concepts.