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

Samba said:   1 decade ago
In C++ we can do
>
> struct Box{
> int x;
> int y;
> void function(){cout<<x<<" "<<y<<endl;};
> }

Harsh said:   1 decade ago
I agree with shivam. Because only class have the membr function structure don't have the member function.

Shivam said:   1 decade ago
Even the option A is correct. We don't have member functions declared in class.

Ashutosh Ghimire said:   1 decade ago
@Ravi Mayank.

You are mixing up C and C++. C is not an OOP.

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

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

Chinmoy said:   1 decade ago
In C++ structure can contain member variable.

Raghava said:   1 decade ago
Can structures in C, have member functions?

Thas said:   1 decade ago
So structure can hold member functions?

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


Post your comments here:

Your comments will be displayed after verification.