1.

What are the differences between a data type struct and data type class in C++?

Answer»
structclass
In C++ struct all members are public by default.Whereas in class all members are private by default.
structures are declared using the keyword structclasses are declared using the keyword class
Example:
struct S1
{
int num; //default access //specifier is public
void setNum(int n)
{
//code
}
};
Example:
class C1
{
 int num; //default access //specifier is private
public:
void setNum(int n)
{
//code
}
};


Discussion

No Comment Found

Related InterviewSolutions