What does the declaration char *arr[10]; signify in C? Explain the type and structure represented by arr in this declaration.

Difficulty: Easy

Correct Answer: arr is a array of 10 character pointers.

Explanation:

Introduction:C declarations can be read using precedence rules. This question probes your ability to parse a declaration that combines pointer and array syntax.

Given Data / Assumptions:

  • Declaration: char arr[10];
  • Standard C declarator binding rules apply.

Concept / Approach:In declarators, [] binds tighter than . Therefore, arr is first an array of 10 elements, and each element has type pointer to char. Thus arr is an array (size 10) of char pointers. It is not a pointer to a single array, nor an array of chars, nor a function pointer.

Step-by-Step Solution:1) Parse inside-out: arr[10] → 'arr is an array of 10'.2) Then apply * to the element type: each element is 'pointer to char'.3) Result: arr is an array of 10 pointers to char.

Verification / Alternative check:Consider typical usage: arr[i] = "hello"; Each arr[i] is of type char, pointing to the first character of a string literal or dynamically allocated buffer.

Why Other Options Are Wrong:Array of function pointer: the element type would include '()()' for functions, which is not present.Array of characters: that would be char arr[10]; without a star.Pointer to array of characters: that would be char (*arr)[N]; with parentheses around *arr.

Common Pitfalls:Misreading precedence or forgetting that [] binds more tightly than *. Parentheses are required to change binding if a pointer-to-array is intended.

Final Answer:arr is a array of 10 character pointers.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion