C++ Programming - OOPS Concepts - Discussion
Discussion Forum : OOPS Concepts - General Questions (Q.No. 21)
21.
Which of the following is correct about class and structure?
Discussion:
23 comments Page 3 of 3.
Shruti said:
8 years ago
In C++, structures can also contain member functons, just like in Class.
Here's an example:
#include<iostream.h>
struct s{
int a;
void f(){ cout<<"hello";}
}ob;
int main()
{
cout << "Welcome!\n" ;
ob.f();
return 0;
}
Output:
Welcome!
hello
Here's an example:
#include<iostream.h>
struct s{
int a;
void f(){ cout<<"hello";}
}ob;
int main()
{
cout << "Welcome!\n" ;
ob.f();
return 0;
}
Output:
Welcome!
hello
Princee sharma said:
6 years ago
There is a difference in structures in c++ and c.
Structures in c can't have member function but c++ can have and so this being question in reference to c++ first option is wrong.
Structures in c can't have member function but c++ can have and so this being question in reference to c++ first option is wrong.
Rahul Shirole said:
4 years ago
Structures in c++ can have member functions like class.
(1)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers