What is the difference between Class and Structure?

Answers were Sorted based on User's Feedback



What is the difference between Class and Structure?..

Answer / swetcha

The difference between a class and a structure is that, by
default, all of the members of a class are private and, by
default, all of the members of a structure are public.

Is This Answer Correct ?    797 Yes 102 No

What is the difference between Class and Structure?..

Answer / p govind rao

1) structure :- In structure have a by default public.
In class have a by default private.
2) Structure cannot be inherited. But class can be
inherit.
3) There is no data hiding features comes with
structures. Classes do, private, protected and public.
4) A structure can't be abstract, a class can.
5) A structure is a value type, while a class is a
reference type.
6) A structure is contain only data member , but class
contain data member and member function.
7) In a Structure we can't initilse the value to the
variable but in class variable we assign the values.
8) Structure are value type, They are stored as a
stack on memory. where as class are reference type. They
are stored as heap on memory.

Is This Answer Correct ?    597 Yes 96 No

What is the difference between Class and Structure?..

Answer / vadivel

i. Structure are value type where as class are reference
type.
ii. Structure are default public where as class are default
private.
iii. 'this' pointer will work only in class.

Is This Answer Correct ?    395 Yes 78 No

What is the difference between Class and Structure?..

Answer / navin

Structure: Initially (in C) a structure was used to bundle
different type of data types together to perform a
particular functionality. But C++ extended the structure to
contain functions also. The major difference is that all
declarations inside a structure are by default public.
Class: Class is a successor of Structure. By default all
the members inside the class are private.

Is This Answer Correct ?    182 Yes 55 No

What is the difference between Class and Structure?..

Answer / anshu sharma

Structure are value types and classes are reference types.So
structures use stack and classes use heap.
Structures members can not be declared as protected , but
class members can be.
You can not do inheritance in structures.
Structures do not require constructors while classes require

Is This Answer Correct ?    158 Yes 54 No

What is the difference between Class and Structure?..

Answer / sundarchum

Structs are Value type. They are stored as a stack on
memory.
Class is reference type. They are stored as heap on memory.
Sturcts constructor must contain a parameter and cannot
have default constructor.
Class constructor may contain no parameter.
Struct cannot have instance field.
Class can have instance field.
Struct cannot inherit from a structure.
Class can inherit from a class.
Structs cannot declare a destructor.

Is This Answer Correct ?    101 Yes 49 No

What is the difference between Class and Structure?..

Answer / mohanraj.d

1.structure is a value type.but class is a reference type.
2.structure is stored in stack.but class is stored in heap.
3.struct cannot have default constructor.
4.struct do not support inheritance.
5.class can inherit from a class.
6.struct cannot have declare destructor.
7.class has define object and function.
8.structure has define only object.

Is This Answer Correct ?    50 Yes 28 No

What is the difference between Class and Structure?..

Answer / rakesh kumar

structure can not be declare privately but class can be
declared public as well as private.In structure data member
and member function are public by default and in class
these are private by default

Is This Answer Correct ?    59 Yes 39 No

What is the difference between Class and Structure?..

Answer / lucky

1) classes can have data member as well as member function but structure is a data type which can have data member only.

Is This Answer Correct ?    40 Yes 31 No

What is the difference between Class and Structure?..

Answer / suresh ghosh

1.class by default used private access specifier but structure used public.
2.class is reference type but structure is value type.
3.class used stack algorithm but structure used heap algorithm.
4.structure don't used public access specifier.
5.class used inheritance but structure don't.

Is This Answer Correct ?    14 Yes 7 No

Post New Answer

More C++ General Interview Questions

What can c++ be used for?

0 Answers  


What is difference between rand () and srand ()?

0 Answers  


Which command properly allocates memory a) char *a=new char[20]; b) char a=new char[20]; c) char a=new char(20.0);

0 Answers  


What are the advantages of pointers?

0 Answers  


What is the difference between an external iterator and an internal iterator? Describe an advantage of the external iterator.

0 Answers  






What is a sequence in c++?

0 Answers  


How the keyword struct is different from the keyword class in c++?

0 Answers  


Find out the bug in this code,because of that this code will not compile....... #include <iostream> #include <new> #include <cstring> using namespace std; class balance { double cur_bal; char name[80]; public: balance(double n, char *s) { cur_bal = n; strcpy(name, s); } ~balance() { cout << "Destructing "; cout << name << "\n"; } void set(double n, char *s) { cur_bal = n; strcpy(name, s); } void get_bal(double &n, char *s) { n = cur_bal; strcpy(s, name); } }; int main() { balance *p; char s[80]; double n; int i; try { p = new balance [3]; // allocate entire array } catch (bad_alloc xa) { cout << "Allocation Failure\n"; return 1; }

2 Answers   Impetus,


What is this pointer in c++?

1 Answers  


What is c++ 11 and c++ 14?

0 Answers  


What is the difference between static link library and dynamic link library?

7 Answers   Tech Mahindra,


Is atoi safe?

0 Answers  


Categories