What is the difference between Class and Structure?




Answers were Sorted based on User's Feedback



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 ?    786 Yes 99 No

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 ?    553 Yes 88 No

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 ?    384 Yes 75 No




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 ?    177 Yes 53 No

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 ?    155 Yes 54 No

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 ?    99 Yes 48 No

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 ?    58 Yes 38 No

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 ?    48 Yes 28 No

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 ?    39 Yes 30 No

Answer / liyakath ulla r

the structurs are used in both c and c++.
but class is used only in c++ and othe opps languages

Is This Answer Correct ?    67 Yes 62 No

Post New Answer



More C++ General Interview Questions

class Foo { public: Foo(int i) { } }; class Bar : virtual Foo { public: Bar() { } }; Bar b; Referring to the above code, when the object 'b' is defined, a compiler error will occur. What action fixes the compiler error? a) Adding a virtual destructor to the class Bar b) Adding a constructor to Bar which takes an int parameter c) Adding "Foo()" to the Bar constructor d) Adding a copy constructor to the class Foo e) Adding "Foo(0)" to the Bar::Bar initializer list

2 Answers   Quark,


what do you mean by memory management operators

4 Answers   HCL,


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  


Shall we use 'free' to free memory assigned by new, What are the further consequences??

5 Answers   Symphony,


advantages and disadvantages of using Borland C++ / version 5.

1 Answers  


In java a final class is a class that cannot be derived. How can you make a similar class in C++

1 Answers  


how many trys can we write in one class

3 Answers   Cap Gemini,


What is the difference between Class and Structure?

39 Answers   IBM, TCS, HP, Samsung,


structure contains int, char, float how it behaves for big endian and little endian?

1 Answers   BITS,


WHO DEVELOPED C++?

6 Answers  


Why is it difficult to store linked list in an array?

6 Answers   Infosys, Lucent,


what is the difference between linear list linked representaion and linked representation? what is the purpose of representing the linear list in linked represention ? is it not avoiding rules of linear represention?

0 Answers  




Categories