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

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

Options

  • B. 85
  • C. Compile-time 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 — 85

Explanation: The member marks is public by default in a struct, so it can be accessed directly using s.marks. The assignment sets it to 85, which is then printed.