0
0
Cprogramming~20 mins

Goto statement overview in C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Goto Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2: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;
}
A0
B5
CCompilation error
DUndefined behavior
Attempts:
2 left
๐Ÿ’ก Hint
The goto skips the assignment to x.
โ“ Predict Output
intermediate
2: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;
}
A0 1 2
BInfinite loop
C0 1 2 3
DCompilation error
Attempts:
2 left
๐Ÿ’ก Hint
The goto creates a loop until i reaches 3.
๐Ÿ”ง Debug
advanced
2: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;
}
ANo error, prints 10 once
BCompilation error: label redefined
CRuntime error: segmentation fault
DInfinite loop at runtime
Attempts:
2 left
๐Ÿ’ก Hint
The goto jumps back to the same label without exit.
๐Ÿ“ Syntax
advanced
2:00remaining
Which option causes a syntax error?
Which of these goto usages causes a syntax error in C?
Agoto start;
Bgoto 123label;
Cend_label: printf("Hi");
Dgoto end_label;
Attempts:
2 left
๐Ÿ’ก Hint
Labels must start with a letter or underscore.
๐Ÿš€ Application
expert
2: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;
}
AInfinite times
B4
C3
D0
Attempts:
2 left
๐Ÿ’ก Hint
The loop stops when count reaches 3.