Difficulty: Easy
Correct Answer: Error: cannot convert parameter 1 from 'const int **' to 'int **'
Explanation:
Introduction / Context:Type qualifiers such as const are part of a variable’s type in C. When you add layers of indirection (pointers to pointers), discarding qualifiers through an implicit conversion becomes dangerous and therefore illegal. This question explores why passing the address of a const int * to a function parameter of type int ** is ill-formed, even though both involve pointers to pointers conceptually.
Given Data / Assumptions:
Concept / Approach:
Step-by-Step Solution:
Caller provides &ptr → type is const int **.Callee expects int ** → types are not compatible.Compiler emits a diagnostic: cannot convert from const int ** to int **.Program fails to compile; no runtime output is produced.Verification / Alternative check:
Consider what would happen if allowed: callee writes an int * pointing to modifiable memory into the location of a const int *; the caller could then modify an object that was intended to be read-only. The restriction prevents this.Why Other Options Are Wrong:
Common Pitfalls:
Final Answer:
Error: cannot convert parameter 1 from 'const int **' to 'int **'
Discussion & Comments