What will be the output of the following C++ code?

#include <iostream>
using namespace std;
class Student
{
public:
    int marks = 85;
};
int main()
{
    Student s;
    cout << s.marks;
    return 0;
}
                        

Options

  • B. 85
  • C. Compilation error
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. 85

Detailed Explanation

Correct Answer: Option B

Explanation:
Student s; creates an object named s. The member marks is initialized to 85 and is public, so it can be accessed using the dot operator: s.marks. The output is 85.