CBSE BOARD XII, asked by ashwethalifecrazy, 8 months ago

What will be the output of this program?#include <iostream>using namespace std; class sample{ int x;} int main(){ sample obj; obj.x=100; cout<<"x="<<obj.x<<endl;} ​

Answers

Answered by sswaraj04
0

Answer:

The variable defined in a class is private by default in C++ and a private variable is only accessed by its own member functions and variables and cant't be used directly by any external link.

so,here x is a privately specified variable and hence can't be accessed by external object defined in different function

so it will return an error and not give any output

Explanation:

Hope it helps:-)

Similar questions