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
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
Political Science,
6 months ago
Math,
6 months ago
English,
6 months ago
Social Sciences,
1 year ago
Social Sciences,
1 year ago