Structure in C++
No doubt, C++ has made various improvements in structure. To know the improvements made in C++, the last program is compiled and executed with C++ compiler. The explanation followed by this program discusses the various improvements.
8.2 Write a program to declare struct. Initialize and display contents of data members.
Explanation: The above program is the same as previous one. The output is also same, hence not shown. Consider the following statement.
item a,*b; // object declaration in c++
While declaring an object, the keyword struct is omitted, which is compulsory in C. The structure item is a user-defined data type. C++ itself behaves as a structure data type which is built-in type and allows variable declaration.
C++ introduces new keyword class, which is similar to structure. The other improvements are discussed with the use of class in the following section.