Bird
0
0

Find the mistake in this C code:

medium📝 Debug Q7 of 15
C - Basics and Execution Environment
Find the mistake in this C code:
int main() {
    int x = 10;
    int *p = &x;
    p = 20;
    return 0;
}
APointer p is not declared
BAssigning integer value directly to pointer variable
CMissing return statement
DIncorrect variable initialization
Step-by-Step Solution
Solution:
  1. Step 1: Analyze pointer assignment

    Pointer p should hold an address, not a direct integer value.
  2. Step 2: Identify invalid assignment

    Assigning 20 directly to p is invalid and causes a type error.
  3. Final Answer:

    Assigning integer value directly to pointer variable -> Option B
  4. Quick Check:

    Pointer must hold address, not integer value [OK]
Quick Trick: Pointers store addresses, not direct integer values [OK]
Common Mistakes:
  • Assigning integer to pointer without & operator
  • Ignoring pointer declaration
  • Assuming missing return causes error here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes