In C/C++, you mark the beginning of a function’s block (compound statement) with which delimiter?

Difficulty: Easy

Correct Answer: {

Explanation:


Introduction / Context:
C and C++ functions contain a body that is a block (also called a compound statement). Correctly marking the start and end of that block is crucial for parsing and for the scope rules that govern variables and control structures. This question asks which symbol begins the block.


Given Data / Assumptions:

  • Language syntax is standard ISO C/C++.
  • A function definition includes a return type, name, parameter list, and a body.
  • The body is a block enclosed in delimiters.


Concept / Approach:

  • A block in C/C++ is delimited by a left brace '{' to begin and a right brace '}' to end.
  • Other symbols such as '/' and '' are used in comments or operators; they are not block delimiters.
  • The delimiters define lexical scope for declarations and control statements.


Step-by-Step Solution:

Write a minimal function: int f() { return 0; }The '{' immediately after the signature starts the function's block; '}' ends it.Therefore, the correct delimiter for beginning the block is '{'.


Verification / Alternative check:

Compilers will emit syntax errors if the opening brace is missing or mismatched, confirming its role as the block opener.


Why Other Options Are Wrong:

  • '/', '*': Not block delimiters; they participate in comments or arithmetic.
  • '}': Closes a block; it does not begin one.
  • either (c) or (d): False; only '{' begins the block while '}' ends it.


Common Pitfalls:

  • Mismatching braces, especially in deeply nested code.
  • Placing declarations outside the intended scope because of misplaced braces.


Final Answer:

{

Discussion & Comments

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