0
0
Cprogramming~20 mins

Variable declaration and initialization - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Variable Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of uninitialized local variable
What is the output of this C code snippet?
C
int main() {
    int x;
    printf("%d", x);
    return 0;
}
A0
BCompilation error
C1
DGarbage value (undefined behavior)
Attempts:
2 left
💡 Hint
Local variables in C are not automatically initialized.
Predict Output
intermediate
2:00remaining
Value of global variable after declaration
What will be printed by this C program?
C
int x;

int main() {
    printf("%d", x);
    return 0;
}
A0
BGarbage value
CCompilation error
DRandom large number
Attempts:
2 left
💡 Hint
Global variables are automatically initialized in C.
Predict Output
advanced
2:00remaining
Output of multiple variable declarations and initializations
What is the output of this code?
C
int main() {
    int a = 5, b, c = 10;
    b = a + c;
    printf("%d %d %d", a, b, c);
    return 0;
}
A5 0 10
B5 15 10
C5 10 10
DCompilation error
Attempts:
2 left
💡 Hint
Check the values assigned and used in the expression.
Predict Output
advanced
2:00remaining
Effect of missing initialization in array declaration
What will be the output of this program?
C
int main() {
    int arr[3];
    printf("%d", arr[0]);
    return 0;
}
A0
B1
CGarbage value (undefined behavior)
DCompilation error
Attempts:
2 left
💡 Hint
Local arrays without initialization contain garbage values.
🧠 Conceptual
expert
2:00remaining
Number of initialized variables in mixed declarations
How many variables are initialized after this declaration?
C
int x = 1, y, z = 3, w;
A2
B3
C4
D1
Attempts:
2 left
💡 Hint
Count only variables with explicit initial values.