Note that in C++, a struct is exactly the same as a class, other than the fact that the members of a struct are public by default while members of a class are private by default, unless explicitly declared otherwise. Aside from that they operate in exactly the same way. In other words, a C++ struct is not the same as a C struct.
There is no advantage because C has no classes. Only C++ has classes.
advantage of storage classes
They are primarily included to retain compatibility with C. However, structures are public by default. So if you don't require the data hiding capability of a class, a struct is a suitable alternative. Also, when mixing C and C++ code, there may be a requirement to typecast a class to a struct and vice versa.
The basic structure of a C or C++ program is built around types. A structure is a type. A function is a type. A class is a type. All of these types can be built from primitive (built-in) types and can be used to create ever-more complex types.
A structure is a collection of variables referenced under one name, providing a convenient means of keeping related information together. A structure declaration forms a template that may be used to create structure objects (that is, instances of a structure). The variables that make up the structure are called members. (Structure members are also commonly referred to as elements or fields).
There is no pressing need for structures in C++. Anything you can do with a structure you can also do with a class. The only real difference is that structure members are public by default, whereas class members are private by default, but they both work exactly the same way otherwise. The struct keyword is retained for backward compatibility with C, but a C++ struct is not the same as a C struct unless it is has no interface and all the member variables are implicitly public. Most C++ programmers will use structures to differentiate simple data structures (values) from fully-encapsulated classes (objects). The complexity of the data and its interface is usually the deciding factor in whether to use a class or a structure. For trivial classes the time and effort that goes into developing the interface is often unnecessary so a structure will often suffice. But if the class is to be distributed to third parties then it's better to provide a more robust interface, even for trivial classes, and to avoid C-style structures entirely.
advantage of storage classes
class is defined in c++ my dear so in C there is no structure of class.for c++ class private { int x[10],y; cout
That depends on the use. Each has advantages in different applications. Without more specifics on your application I cannot comment usefully.
They are primarily included to retain compatibility with C. However, structures are public by default. So if you don't require the data hiding capability of a class, a struct is a suitable alternative. Also, when mixing C and C++ code, there may be a requirement to typecast a class to a struct and vice versa.
The main difference between a class and a structure is that structures are always public whereas classes are private by default. Classes give greater control as the interface can be engineered such that only code that requires access to specific class members gains that access. Everything else can be hidden within the class itself. Note that C does not support classes, period. Classes are only supported by C++. However C++ also supports C structures for backward compatibility with C-style code.
There are no advantages of C over C++ as such. Everything you can do in C you can also do in C++. However, by taking advantage of C++ object oriented programming, generic programming and template meta programming as well as C-style coding, you can produce more efficient machine code far more easily and more quickly than with C alone.
Because piping class B was over populated, they needed a new piping class. For some reason they decided to skip C and go straight to piping class D
The basic structure of a C or C++ program is built around types. A structure is a type. A function is a type. A class is a type. All of these types can be built from primitive (built-in) types and can be used to create ever-more complex types.
A structure is a collection of variables referenced under one name, providing a convenient means of keeping related information together. A structure declaration forms a template that may be used to create structure objects (that is, instances of a structure). The variables that make up the structure are called members. (Structure members are also commonly referred to as elements or fields).
I guess you mean C++, not C.Data fields of a structure/union are public by default,those of a class are private by default.
Structures are public by default whereas classes are private by default. Other than that they are exactly the same. struct s { int num; // s.num is accessible outside of the structure }; class c { int num; // c.num is only accessible to the class itself. };
In class default members are private and in structure default members are public ,When ever you want to hide data from outside functions then you can use class.But in ANSI C we can hide data by using private access specifier.