C/C++ fundamentals: At what stage do we 'mention' (provide) the prototype of a function—defining, declaring, prototyping, or calling?

Difficulty: Easy

Correct Answer: Declaring

Explanation:


Introduction / Context:
A function prototype communicates a function's name, return type, and parameter types to the compiler before the function is used. This is critical for type checking, overload resolution (C++), and correct code generation. The question asks at which stage we provide that prototype in normal C/C++ development flow.


Given Data / Assumptions:

  • A function's signature must be known to the compiler before it is called.
  • Prototypes are typically placed in header files that are included where needed.
  • We distinguish between declaration (prototype) and definition (body).


Concept / Approach:

  • A declaration introduces an identifier and its type; for functions, that is the prototype.
  • A definition provides the actual function body.
  • Calling is the act of invoking a function; it requires that a declaration is already visible.


Step-by-Step Solution:

Identify what a prototype contains: return type + name + parameter types.Recognize that providing this information is exactly a function declaration, not a definition.Therefore, the stage is Declaring.


Verification / Alternative check:

Example: 'int sum(int a, int b);' (declaration/prototype) can appear in a header; the body appears in a source file.


Why Other Options Are Wrong:

  • Defining: Includes the body; the prototype exists even without the body.
  • Prototyping: Not a standard stage name; the correct term is 'declaring'.
  • Calling: Requires that the prototype (declaration) already be known.


Common Pitfalls:

  • Confusing the term 'prototype' with the implementation; only the signature is needed to call.
  • Omitting prototypes leads to implicit declarations (illegal in modern C) or compiler errors.


Final Answer:

Declaring

Discussion & Comments

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