Bird
0
0

Identify the error in this code snippet: const int num = 5; num = 10;

medium📝 Debug Q6 of 15
C - Variables and Data Types
Identify the error in this code snippet: const int num = 5; num = 10;
ACannot assign to a constant variable
BNo error, code runs fine
CMissing semicolon after declaration
Dnum should be declared as a pointer
Step-by-Step Solution
Solution:
  1. Step 1: Understand const keyword

    const means the variable's value cannot be changed after initialization.
  2. Step 2: Check assignment

    Assigning 10 to num after declaration violates const rule, causing error.
  3. Final Answer:

    Cannot assign to a constant variable -> Option A
  4. Quick Check:

    const variables cannot be reassigned [OK]
Quick Trick: const variables cannot be changed after initialization [OK]
Common Mistakes:
  • Trying to reassign const variables
  • Ignoring const keyword effects

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes