nerdexam
Python_Institute

PCEP-30-02 · Question #203

A function definition:

The correct answer is C. must be placed before the first invocation. Option C is correct because in most structured programming languages (such as C, Pascal, and Python), the interpreter or compiler processes code sequentially - it must know a function's signature and body before it can execute a call to it. Placing the definition after the…

Question

A function definition:

Options

  • Acannot be placed among other code
  • Bmay be placed anywhere inside the code after the first invocation
  • Cmust be placed before the first invocation

How the community answered

(41 responses)
  • A
    7% (3)
  • B
    15% (6)
  • C
    78% (32)

Explanation

Option C is correct because in most structured programming languages (such as C, Pascal, and Python), the interpreter or compiler processes code sequentially - it must know a function's signature and body before it can execute a call to it. Placing the definition after the first invocation causes a "function not defined" or "undeclared identifier" error at compile or runtime.

Option A is wrong because function definitions can appear among other code - they just must appear in the right position (before the first call), not necessarily at the very top of the file.

Option B is wrong because it inverts the required order; placing a definition after the first invocation means the program encounters the call before knowing what the function is, which fails.

Memory tip: Think of it like introducing someone at a party - you have to introduce them before you can ask others to go talk to them. Define first, call later.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice