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

Answers were Sorted based on User's Feedback



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

Answer / rsn

Hello Shivani,

I think both struct and class in C++ are quite the same
except for the fact that, members in struct are public by
default whereas they are private for class.
Moreover struct also supports inheritance,polymorphism
etc...etc...

Is This Answer Correct ?    14 Yes 0 No

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

Answer / amit patel

Rsn answer is perfect write.Shivani you are wrong.
the visiblity of members default public in structure,
whereas in class its private as all know.
So please don't make myths here.

for the detail answer for explanation read the following link.

http://carcino.gen.nz/tech/cpp/struct_vs_class.php

Is This Answer Correct ?    5 Yes 2 No

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

Answer / ramesh kasi

The only difference is related to the default access
specifier.
The members of a structure have public access by default.
The members of a calss have private access by default.

Is This Answer Correct ?    3 Yes 1 No

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

Answer / supriya

Memory is alloated on Stack using Structure whereas in class its heap , that is it wont be stored at an contagious memory location.

Is This Answer Correct ?    0 Yes 0 No

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

Answer / ajit

In structures by default the member variables considered as
public where as in classes by default data members are
considered as private.
Structures doesn't provide the concept data encapsulation
but classes provides it.

Is This Answer Correct ?    0 Yes 1 No

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

Answer / shivani

In Class Members are private by default.
In Structure Member are public by default.
structures are value typed where as classes are refernce
typed

Class can be inherited But Structure can't be inherited

In structures we cannot initilase the variable during the
declaration while in classes we can.

Structure s does not support polymorphism while class does

Structure can be declared without a tag at the first time,
but not in case of class.

e.g. struct { variables; }(struct variable list); [It would
not raise any error while comlitation]

class { access specifier: variable list; access specifier:
vari....

}; [it will cause an error while compilation]

Is This Answer Correct ?    3 Yes 6 No

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

Answer / rajesh

shivani is wrong bec. structure is not inherited.

Is This Answer Correct ?    0 Yes 6 No

Post New Answer

More C++ General Interview Questions

What is guard code in c++?

0 Answers  


How to detect memory leaks in c++

1 Answers   Mphasis,


Describe run-time type identification?

1 Answers  


What are the total number of lines written by you in C/C++? What is the most complicated or valuable program written in C/C++?

2 Answers   Intel,


What things would you remember while making an interface?

0 Answers  






What is Object Oriented programming.what is the difference between C++ and C?

8 Answers   Infosys,


When can I use a forward declaration?

0 Answers  


What is an operator function? Describe the function of an operator function?

0 Answers   Fidelity,


You're given an array containing both positive and negative integers and required to find the sub-array with the largest sum (O(N) a la KBL). Write a routine in C for the above.

4 Answers  


Out of fgets() and gets() which function is safe to use?

0 Answers  


Which field is used in c++?

0 Answers  


Can I uninstall microsoft c++ redistributable?

0 Answers  


Categories