26.1k views
4 votes
What does the following piece of code do:

Object obj();

A) Creates an object named 'obj'
B) Declares a function named 'obj'
C) Invokes the default constructor of the 'Object' class
D) Results in a compilation error

User Cosmin D
by
8.5k points

1 Answer

3 votes

Final answer:

The given piece of code declares a function named 'obj'.

Step-by-step explanation:

The given piece of code: Object obj(); declares a function named 'obj'.

In C++, when you want to declare a variable of a class type, you do not need to include the parentheses after the class name. However, when the parentheses are included, it is interpreted as a function declaration rather than an object declaration.

Therefore, the correct answer is B) Declares a function named 'obj'.

User AshuKingSharma
by
8.5k points