Difficulty: Easy
Correct Answer: Error: cannot convert parameter 1 from const int * to int *
Explanation:
Introduction / Context:Const-correctness ensures that objects declared read-only are not modified inadvertently. When a function takes an int *, passing it the address of a const int violates that promise. Even though some legacy compilers accept such code with only a warning, the intent of the language is to forbid discarding const implicitly. This question examines the compile-time consequence of attempting to modify a const array element through a non-const pointer parameter.
Given Data / Assumptions:
Concept / Approach:
Step-by-Step Solution:
Identify parameter type mismatch: fun expects int * but receives const int *.Implicit cast would remove const → forbidden.Compiler issues a diagnostic; the program should not compile successfully.Verification / Alternative check:
If you change fun to accept const int * and remove the write, the call compiles. If you remove const from arr, the original fun compiles and sets arr[3] to 10.Why Other Options Are Wrong:
Common Pitfalls:
Final Answer:
Error: cannot convert parameter 1 from const int * to int *
Discussion & Comments