C syntax rule: “A function cannot be defined inside another function.” Decide whether this statement is correct or incorrect (standard ISO C, not extensions).

Difficulty: Easy

Correct Answer: Correct

Explanation:


Introduction / Context:
This concept checks whether ISO C permits nested function definitions. Some compilers (like GCC) offer an extension for nested functions, which can cause confusion. Standard C forbids defining a function inside the body of another function.



Given Data / Assumptions:

  • We refer to ISO C (C99/C11/C17/C23), not compiler-specific extensions.
  • Function declarations (prototypes) may appear in block scope, but definitions may not.


Concept / Approach:
In standard C, a function definition has external or file scope and cannot be nested in the compound statement of another function. Placing a full definition within another function violates the grammar. GCC’s nested functions are a nonportable extension and should not be relied upon in portable code.



Step-by-Step Solution:
Interpret the statement under ISO C rules.Note: Only declarations (prototypes) are permitted inside blocks; definitions are not.Therefore, the statement is correct for standard C.



Verification / Alternative check:
Attempting “void outer(){ void inner(){} }” in a strict standard C mode (e.g., -std=c11 -pedantic) produces an error. Moving inner to file scope resolves it.



Why Other Options Are Wrong:
Incorrect/inline/static/linker options: none change the language grammar that forbids nested definitions.



Common Pitfalls:
Confusing declarations with definitions; assuming behavior seen with a GNU extension is portable.



Final Answer:
Correct

More Questions from Functions

Discussion & Comments

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