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

write a programme to get a character and thier ASCII value

0 Answers  


Write about the retrieval of n number of objects during the process of delete[]p?

0 Answers  


What is else syntax in c++?

0 Answers  


What is a virtual destructor? Explain the use of it?

0 Answers  


What are the advantages of prototyping?

0 Answers  






Define pure virtual function?

0 Answers  


What is friend class in c++ with example?

0 Answers  


what is software cycle? What is a mission critical system ? What is the important aspect of a real-time system ? Explain the difference between microkernel and macro kernel. Give an example of microkernel.Why paging is used ? Which is the best page replacement algo and Why ? What is software life cycle ? How much time is spent usually in each phases and why Which one do U want to work if selected in Honeywell ? Which are the different types of testing ? What is a distributed system ? Some questions about CSP. Which languages do U know ? What are the differences between Pascal and C. questions from Compiler construction and Lisp. Which are the different computer architecture? What is the requirement in MIMD ? What is the difference between RISC and CISC processors ? Difference between loosely coupled and tightly coupled systems ? What is an open system?

0 Answers   Honeywell,


What are C++ inline functions?

1 Answers  


What is the difference between passing by reference and passing a reference?

0 Answers  


Is there a c++ certification?

0 Answers  


What is function prototyping?

0 Answers  


Categories