Challenge - 5 Problems
Goto Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of a simple goto jump
What is the output of this C program?
C
#include <stdio.h> int main() { int x = 0; goto skip; x = 5; skip: printf("%d", x); return 0; }
Attempts:
2 left
๐ก Hint
The goto skips the assignment to x.
โ Incorrect
The goto jumps over the line 'x = 5;', so x remains 0. The program prints 0.
โ Predict Output
intermediate2:00remaining
Effect of goto inside a loop
What is the output of this C code?
C
#include <stdio.h> int main() { int i = 0; start: if (i >= 3) goto end; printf("%d ", i); i++; goto start; end: return 0; }
Attempts:
2 left
๐ก Hint
The goto creates a loop until i reaches 3.
โ Incorrect
The code prints 0, 1, 2 with spaces, then exits when i is 3.
๐ง Debug
advanced2:00remaining
Identify the error caused by goto
What error does this C code produce when compiled or run?
C
#include <stdio.h> int main() { int x = 10; goto label; x = x + 5; label: printf("%d", x); goto label; return 0; }
Attempts:
2 left
๐ก Hint
The goto jumps back to the same label without exit.
โ Incorrect
The code jumps to 'label' and then jumps back to 'label' again, causing an infinite loop printing 10 repeatedly.
๐ Syntax
advanced2:00remaining
Which option causes a syntax error?
Which of these goto usages causes a syntax error in C?
Attempts:
2 left
๐ก Hint
Labels must start with a letter or underscore.
โ Incorrect
Label names cannot start with a digit. '123label' is invalid syntax.
๐ Application
expert2:00remaining
How many times is the word printed?
How many times will the word "Hello" be printed by this C program?
C
#include <stdio.h> int main() { int count = 0; start: if (count == 3) goto end; printf("Hello\n"); count++; goto start; end: return 0; }
Attempts:
2 left
๐ก Hint
The loop stops when count reaches 3.
โ Incorrect
The program prints "Hello" three times before jumping to end and stopping.