Difficulty: Easy
Correct Answer: Error
Explanation:
Introduction / Context:
This question checks your understanding of pointer arithmetic rules in C. While pointers can be incremented or decremented by integers to traverse arrays, adding two pointers to each other is not a valid operation and will be rejected by the compiler.
Given Data / Assumptions:
Concept / Approach:
Legal pointer arithmetic allows expressions like ptr + integer or ptr - integer (to move within the same array) and ptr1 - ptr2 (to compute distance within the same array). However, ptr1 + ptr2 is invalid because the result has no well-defined meaning in C. A conforming compiler diagnoses this as an error at compile time.
Step-by-Step Solution:
Verification / Alternative check:
Replacing the line with int j = atoi(argv[1]) + atoi(argv[2]) + atoi(argv[3]); compiles and prints 6 for the given invocation.
Why Other Options Are Wrong:
Common Pitfalls:
Assuming pointers behave like integers in all arithmetic contexts; forgetting that only pointer±integer and pointer–pointer (same array) are permitted operations.
Final Answer:
Error
Discussion & Comments