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 / vandana mishra

Class is much broader,real world applicable 1-1-1: concept whereas structure is a primitive concept with poor internal organisation.
2: structure contains only data while class bind both data & member functions.
3: class provide data hiding,inheritance etc but structure didn't.
4: if we not define constructor in class there constructor automaticly invoke but in structure it does not happen automaticly.

Is This Answer Correct ?    0 Yes 0 No

What is the difference between Class and Structure?..

Answer / uppu goutami

In C++, A structure can have both variable and functions as members.It can also declare some of its members as 'private' so that they cannot be accessed directly by the external functions.
In C++, The structure names are stand-alone and can be used like any other type names. That is, the keyword 'struct' can be omitted in the declaration of structure variable.
For example, We can declare the student variable.
For student A; // c++ declaration
This is an error in C.
C++ incorporates all these extensions in another user-defined type known as 'class'. There is very little syntactical difference between class and structure in C++ and, therefore, They can be used interchangeably with minor modifications. Since 'class' is a specially introduced data type, most of the C++ programmers tend to use the structures for holding only data, and classes to hold both the data and functions.

Is This Answer Correct ?    0 Yes 0 No

What is the difference between Class and Structure?..

Answer / riyaz

Class Can be abstract but structure can't
Class support inheritance but sturcutre can't
Class allows modifiers such as public,private but structure by default allow public
Class can used for huge amount of data, structure is for limited amount of data

Is This Answer Correct ?    0 Yes 0 No

What is the difference between Class and Structure?..

Answer / prince rupela

1.Structure is Value Type. Class is a reference type.
2.Structure Contain Data Member. Class Contain Data Member And Member Function.
3.In Structure Data Members are By Default Public. In Class Data Member are By Default Private
4.Structure can not Inherit. Structure can Inherit.
5.There is no Data Hiding Feature in Structure. In Class There is Data Hiding features like Public,Private, Protected.
6.A Structure Can't Abstract . Class can.
7.Structure both use c and c++. class only c++ and oops language.

Is This Answer Correct ?    0 Yes 0 No

What is the difference between Class and Structure?..

Answer / sanjay yadav

# 5
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.

structure :- In structure have a by default public.
In class have a by default private.
Structure cannot be inherited. But class can be
inherit.
There is no data hiding features comes with
structures. Classes do, private, protected and public.
A structure can't be abstract, a class can.
A structure is a value type, while a class is a
reference type.
A structure is contain only data member , but class
contain data member and member function.
In a Structure we can't initilse the value to the
variable but in class variable we assign the values.
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 ?    1 Yes 2 No

What is the difference between Class and Structure?..

Answer / ali abbas khan

structure is contain data member and class is contain member function
structure have by default public and class have by default privat
structure can't have inheritance and class can have inheritance

Is This Answer Correct ?    0 Yes 1 No

What is the difference between Class and Structure?..

Answer / bitdeveloper

<a
href="http://questionscompiled.com/answer.jsp?technology=cpp&qid=141">questionscompiled.com</a>

Classes and Structures in C++ are same except class defaults
to private and structures to public. They can have data
members, member function, this pointer, static member functions.

Is This Answer Correct ?    0 Yes 1 No

What is the difference between Class and Structure?..

Answer / amit

strucuter member function and variable are by defualt
public and class member varible and funtion are by defualt
private.
sructure can not inherited but class can .

Is This Answer Correct ?    0 Yes 2 No

What is the difference between Class and Structure?..

Answer / anand

structure is used space in memory permanently but in class members are not used space permanently there is erase with the time and use other member this memory space

Is This Answer Correct ?    0 Yes 2 No

What is the difference between Class and Structure?..

Answer / ashish agarwal

1. Classes are reference types and structs are value types.
Since classes are reference type, a class variable can be assigned null.But we cannot assign null to
a struct variable, since structs are value type.
2. When you instantiate a class, it will be allocated on the heap.When you instantiate a struct, it gets created on the stack.
3. You will always be dealing with reference to an object ( instance ) of a class. But you will not be dealing with references to an instance of a struct ( but dealing directly with them ).
4. When passing a class to a method, it is passed by reference. When passing a struct to a method, it’s passed by value instead of as a reference.
5. You cannot have instance Field initializers in structs.But classes can have
example:class MyClass
{
int myVar =10; // no syntax error.
public void MyFun( )
{
// statements
}
}
struct MyStruct
{
int myVar = 10; // syntax error.
public void MyFun( )
{
// statements
}
}
6. Classes can have explicit parameterless constructors. But structs cannot have
7. Classes must be instantiated using the new operator. But structs can be
8. Classes support inheritance.But there is no inheritance for structs.
( structs don’t support inheritance polymorphism )
9. Since struct does not support inheritance, access modifier of a member of a struct cannot be protected or protected internal.11. A class is permitted to declare a destructor.But a struct is not
12. classes are used for complex and large set data. structs are simple to use.

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More C++ General Interview Questions

Differentiate between declaration and definition in C++?

1 Answers  


Program to check whether a word is a sub-string or not of a string typed

0 Answers  


Explain virtual class and friend class.

0 Answers  


What are raw sockets, where they are efficient?

2 Answers   Symphony,


How a modifier is similar to mutator?

0 Answers  






Do you know what are static and dynamic type checking?

0 Answers  


How to allocate memory dynamically for a reference?

0 Answers  


How can you prevent accessing of the private parts of my class by other programmers (violating encapsulation)?

0 Answers  


What is double in c++?

0 Answers  


What is the full name of logo?

0 Answers  


write a program to add two numbers without using an arithmetic operator.

1 Answers   NIIT,


What is a pure virtual function? Why is it represented as = 0...how is the internal implementation for the same

3 Answers   CTS,


Categories