Q:

C++ program to access public data member inside main using object name.

belongs to collection: C++ programs on various topics

0

C++ program to access public data member inside main using object name.

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C++ program (Code Snippet) – Accessing public data member (Variable) inside main function using Object Name

Let’s consider the following example:

/*C++ program to access public data member 
inside main using object name*/

#include <iostream>

using namespace std;

class Sample{
	public:
		int x;
};

int main(){
	Sample objSample;
	objSample.x=20;
	cout<<"value of x: "<<objSample.x<<endl;
	return 0;
}

Output

            value of x: 20

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ programs on various topics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C++ program to declare, define and access public s... >>
<< C++ program to demonstrate use of protected data m...