In C structure
1) We can not have access specifiers
2) Can not have functions.
But in C++
1) We can specify data and functions as public Private or protected.
In C++ structure is also a class with Private as default access specifier
C++ places greater emphasis on type checking, compiler can diagnose every difference between C and C++.
1. structures are a way of storing many different values in variables of potentially difference types under the same name.
2. classes and structures make program modular, easier to modify make things compact.
3. useful when a lot of data needs to be grouped together.
4. struct Tag {…}struct example {Int x;}example ex; ex.x = 33; //accessing variable of structure.
5. members of a struct in C are by default public, in C++ private.
6. unions like structs except they share memory – allocates largest data type in memory – like a giant storage: store one small OR one large but never both at the same time.
7. pointers can point to struct:
8. C++ can use class instead of struct (almost the same thing) – difference: C++ classes can include functions as members.
9. members can be declared as: private: members of a class are accessible only from other members of their same class; protected: members are accessible from members of their same class and friend classes and also members of their derived classes; public: members are accessible from anywhere the class is visible.
10. structs usually used for data only structures, classes for classes that have procedures and member functions.
11. use private because in large projects important that values not be modified in an unexpected way from the POV of the object.
Build Your Own Test Framework
-
[image: Build Your Own Test Framework]
Learn to write better automated tests that will dramatically increase your
productivity and have fun while doing so...
37 minutes ago
No comments:
Post a Comment
I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.