Challenge - 5 Problems
Variable Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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; }
Attempts:
2 left
💡 Hint
Local variables in C are not automatically initialized.
✗ Incorrect
Local variables declared without initialization contain garbage values, leading to undefined behavior when printed.
❓ Predict Output
intermediate2: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; }
Attempts:
2 left
💡 Hint
Global variables are automatically initialized in C.
✗ Incorrect
Global variables in C are initialized to zero by default if not explicitly initialized.
❓ Predict Output
advanced2: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; }
Attempts:
2 left
💡 Hint
Check the values assigned and used in the expression.
✗ Incorrect
Variable a is 5, c is 10, b is assigned a + c = 15. So printing a, b, c outputs 5 15 10.
❓ Predict Output
advanced2: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; }
Attempts:
2 left
💡 Hint
Local arrays without initialization contain garbage values.
✗ Incorrect
Local arrays in C are not initialized automatically, so arr[0] contains garbage value.
🧠 Conceptual
expert2:00remaining
Number of initialized variables in mixed declarations
How many variables are initialized after this declaration?
C
int x = 1, y, z = 3, w;
Attempts:
2 left
💡 Hint
Count only variables with explicit initial values.
✗ Incorrect
Only x and z are initialized explicitly; y and w are declared but uninitialized.