class sample{ int a; public: void set_a(int n) {a=n;} int get_a( ) {return a} }; int main() { sample ob[4]; int i; for(i=0; i<4; i++) ob[i].set_a(i); for(i=0; i<4; i++) cout<< ob[i].get_a( ); cout<<" \n"; return 0; }
Liked By
Write Answer
How to create a array of objects in c ?
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy
Join MindStick Community
You have need login or register for voting of answers or question.
AVADHESH PATEL
15-Jun-2013class sample{int a;
public:
void set_a(int n) {a=n;}
int get_a( ) {return a}
};
int main()
{
sample ob[4];
int i;
for(i=0; i<4; i++) ob[i].set_a(i);
for(i=0; i<4; i++) cout<< ob[i].get_a( );
cout<<" \n";
return 0;
}