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 1 of 3.
Rahul Shirole said:
4 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.
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
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:
9 years ago
Anybody can explain option A, in detailed form?
Bhavin panchal said:
9 years ago
Option A also true.
Sumit said:
10 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.
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:
1 decade ago
Can structures in C, have member functions?
Vikas Pareek said:
1 decade 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:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers