Difference between C structures and C++ structures

CC++Server Side ProgrammingProgramming

Here we will see what are the differences between structures in C and structures in C++. The C++ structures are mostly like classes in C++. In C structure, all members are public, but in C++, they are private in default. Some other differences are listed below.

C StructureC++ Structure
Structures in C, cannot have member functions inside structures.Structures in C++ can hold member functions with member variables.
We cannot initialize the structure data directly in C.We can directly initialize structure data in C++.
In C, we have to write ‘struct’ keyword to declare structure type variables.In C++, we do not need to use ‘struct’ keyword for declaring variables.
C structures cannot have static members.C++ structures can have static members.
The sizeof operator will generate 0 for empty structure in CThe sizeof operator will generate 1 for empty structure in C++
The data hiding feature is not available in C structures.The data hiding feature is present in C++ structures.
C structures does not have access modifiers.C++ structures have access specifiers.
raja
Published on 26-Apr-2019 16:02:33
Advertisements