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?
class can have member functions while structure cannot.
class data members are public by default while that of structure are private.
Pointer to structure or classes cannot be declared.
class data members are private by default while that of structure are public by default.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
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

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.

Rahul Shirole said:   4 years ago
Structures in c++ can have member functions like class.
(1)


Post your comments here:

Your comments will be displayed after verification.