No products in the cart.

Difference between class and structure

CBSE, JEE, NEET, CUET

CBSE, JEE, NEET, CUET

Question Bank, Mock Tests, Exam Papers

NCERT Solutions, Sample Papers, Notes, Videos

Difference between class and structure
  • 1 answers

Sia ? 3 years, 5 months ago

<th>Class</th> <th>Structure</th>
Classes are of reference types. Structs are of value types.
All the reference types are allocated on heap memory. All the value types are allocated on stack memory.
Allocation of large reference type is cheaper than allocation of large value type. Allocation and de-allocation is cheaper in value type as compare to reference type.
Class has limitless features. Struct has limited features.
Class is generally used in large programs. Struct are used in small programs.
Classes can contain constructor or destructor. Structure does not contain parameter less constructor or destructor, but can contain Parameterized constructor or static constructor.
Classes used new keyword for creating instances. Struct can create an instance, with or without new keyword.
A Class can inherit from another class. A Struct is not allowed to inherit from another struct or class.
The data member of a class can be protected. The data member of struct can’t be protected.
Function member of the class can be virtual or abstract. Function member of the struct cannot be virtual or abstract.
Two variable of class can contain the reference of the same object and any operation on one variable can affect another variable. Each variable in struct contains its own copy of data(except in ref and out parameter variable) and any operation on one variable can not effect another variable.
http://mycbseguide.com/examin8/

Related Questions

What are called tokens
  • 2 answers
What is mean by buffering in file handling?
  • 1 answers

myCBSEguide App

myCBSEguide

Trusted by 1 Crore+ Students

Test Generator

Test Generator

Create papers online. It's FREE.

CUET Mock Tests

CUET Mock Tests

75,000+ questions to practice only on myCBSEguide app

Download myCBSEguide App