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 1 of 3.

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

Princee sharma said:   5 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.

Shruti said:   7 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

Manpreet said:   8 years ago
I think A is also the correct answer.

BADAL MAITY said:   8 years ago
The option A is correct.

Priya said:   8 years ago
Anybody can explain option A, in detailed form?

Bhavin panchal said:   8 years ago
Option A also true.

Sumit said:   9 years ago
No, structure can't have a member functions.

The fundamental difference between C and C++. C++ supports classes (and in C++ a struct is a special case of a class), and C does not.

Raghava said:   10 years ago
Can structures in C, have member functions?

Vikas Pareek said:   10 years ago
Option A is correct as well because this is the difference between Classes and structures that structures cannot have member functions while classes can.


Post your comments here:

Your comments will be displayed after verification.