C declarations: interpret the following declaration char *scr;

Difficulty: Easy

Correct Answer: scr is a pointer to char.

Explanation:


Introduction / Context:
This item tests basic pointer declarations in C. The expression char *name; is one of the most common idioms and denotes a pointer that can reference a character or the first element of a character array representing a C string.


Given Data / Assumptions:

  • Declaration under analysis: char *scr;
  • No qualifiers (const, volatile) or storage specifiers are present.
  • We are only classifying the type, not its initialization or lifetime.


Concept / Approach:

In C, the * binds to the identifier as part of the declarator, so char *scr; defines scr as “pointer to char”. This pointer can hold the address of a single char object or the first element of a char buffer that is terminated with '\\0' to represent a string. The declaration does not allocate storage for characters; it only allocates space for the pointer itself.


Step-by-Step Solution:

1) Identify base type: char. 2) Apply pointer declarator * to the identifier: *scr. 3) Conclude scr has type char* (pointer to char). 4) Usage typically involves assignment from &ch or from a string literal to a const-qualified pointer when appropriate.


Verification / Alternative check:

sizeof(scr) equals the size of a pointer on the platform, not the size of a character buffer. Dereferencing *scr yields type char, which confirms the one-level indirection.


Why Other Options Are Wrong:

Pointer to pointer — Would require char **scr.

Function pointer — No function declarator () exists.

Member of function pointer — Not meaningful terminology in C type system.


Common Pitfalls:

  • Assuming char *scr allocates storage for a full string; it does not allocate the characters themselves.
  • Forgetting const when pointing to string literals to avoid modifying read-only storage.


Final Answer:

scr is a pointer to char.

More Questions from Complicated Declarations

Discussion & Comments

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