Skip to content
Question of 97

Q.Rewrite the following C++ program after removing any/all syntactical error(s). Underline each correction done in the code: Note : Assume all required header files are already included in the program. #define Area(L,B) = L*B structure Recta { int Length,Breadth; }; void main() { Recta R = [10,15]; cout<<Area(Length.R,Breadth.R); }

CBSECBSE Class XII Board 2019Subjective· 2mImportance★★★★★est
0% · 0/97 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

The code has five syntactical errors: an incorrect macro definition with =, wrong structure keyword, invalid aggregate initialization syntax, incorrect member access order, and wrong main() return type. The corrected program compiles and runs properly.

This is a debugging exercise that tests your understanding of C++ syntax across macros, structures, initialization, and member access. Each error violates a specific rule of C++ grammar.

The original code attempts to define a macro for calculating area, declare a structure for a rectangle, create an instance, and print the area. However, it contains multiple syntax violations that prevent compilation.

Errors and Corrections

  1. Macro definition with assignment operator

    The line #define Area(L,B) = L*B is incorrect because preprocessor macros don't use =. A macro definition directly replaces tokens.

    Correction: <u>#define Area(L,B) L*B</u>

  2. Wrong keyword for structure

    C++ uses struct, not structure.

    Correction: <u>struct Recta</u>

  3. Invalid initialization syntax

    The line Recta R = [10,15]; uses square brackets, which is not valid for structure initialization in C++. Aggregate initialization requires curly braces.

    Correction: <u>Recta R = {10,15};</u>

  4. Incorrect member access syntax

    Length.R reverses the correct order. The object name comes first, then the dot operator, then the member name.

    Correction: <u>R.Length</u> and <u>R.Breadth</u>

  5. Wrong return type for main()

    In standard C++, main() must return int, not void. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.