Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Difference Between Structure and Class in C++

In C++, a structure works the same way as a class, except for just two small differences. The most
important of them is hiding implementation details. A structure will by default not hide its
implementation details from whoever uses it in code, while a class by default hides all its implementation
details and will therefore by default prevent the programmer from accessing them. The following table
summarizes all of the fundamental differences.

Class Structure

1. Members of a class are private by default. 1. Members of a structure are public by default.

2. An instance of structure is called the ‘structure


2. An instance of a class is called an ‘object’.
variable’.

3. Member classes/structures of a class are private


3. Member classes/structures of a structure are
by default but not all programming languages have
public by default.
this default behavior eg Java etc.

4. It is declared using the class keyword. 4. It is declared using the struct keyword.

5. It is normally used for data abstraction and


5. It is normally used for the grouping of data
further inheritance.

6. NULL values are possible in Class. 6. NULL values are not possible.

7. Syntax: 7. Syntax:

class class_name{ struct structure_name{

data_member; type structure_member1;

member_function; type structure_member2;

}; };

You might also like