Interview Preparation Difference between C structure and C++ structure?

Monday, July 11, 2011
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.

0 Comments:

Post a Comment

comment

 
 
 

Recent Posts

New User Register Here

 
Copyright © 2010-2011 Find Out What You Want
Bloggerized by Mangesh Shinde