What Are The Differences Between A C++ Struct And C++ Class?

Answers were Sorted based on User's Feedback



What Are The Differences Between A C++ Struct And C++ Class?..

Answer / nikhil upadhyay

The default member and base-class access specifiers are different.
This is one of the commonly misunderstood aspects of C++. Believe it or not, many programmers think that a C++ struct is just like a C struct, while a C++ class has inheritance, access specifiers, member functions, overloaded operators, and so on. Some of them have even written books about C++. Actually, the C++ struct has all the features of the class. The only differences are that a struct defaults to public member access and public base-class inheritance, and a class defaults to the private access specifier and private base-class inheritance. Getting this question wrong does not necessarily disqualify an applicant. Getting it right is a definite plus.
Saying, "I don't know" is definitely the wrong answer. I advance an unusual position about this. C++ programmers should at least believe that they know the differences, even when they are wrong about them. Getting it wrong is, therefore, right. You can explain the true difference in the interview and advance the programmer's knowledge. If they disagree vociferously, you have an opportunity to observe how they handle contentious debate when they are wrong and don't know it yet.

Is This Answer Correct ?    0 Yes 0 No

What Are The Differences Between A C++ Struct And C++ Class?..

Answer / shalesh kumar

The default member and base-class access specifies are different.

This is one of the commonly misunderstood aspects of C++. Believe it or not, many programmers think that a C++ struct is just like a C struct, while a C++ class has inheritance, access specifies, member functions, overloaded operators, and so on. Actually, the C++ struct has all the features of the class. The only differences are that a struct defaults to public member access and public base-class inheritance, and a class defaults to the private access specified and private base-class inheritance.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ Interview Questions

How does stack look in function calls? When does stack overflow? What can you do to remedy it?

0 Answers   Adobe,


It is possible to build a C++ compiler on top of a C compiler. How would you do this?

0 Answers   Amazon,


Explain the FOR loop with a help of a code.

0 Answers   Accenture,


CDPATH shell variable is in(c-shell)

0 Answers   Siemens,


What is a virtual function in C++?

0 Answers   C DAC,






How do you write a function that can reverse a linked-list in C++?

0 Answers   IBS,


Declare a pointer to a function that takes a char pointer as argument and returns a void pointer.

0 Answers   Alter,


What does malloc return in C and C++?

0 Answers   Alter,


What are the advantages/disadvantages of using #define?

0 Answers   Amazon,


What is name mangling/name decoration?

0 Answers   Amazon,


What does it mean to declare a member function as static in C++?

0 Answers   Amazon,


What is the difference between member functions and static member functions?

0 Answers   Alter,


Categories