Differentiate between class and structure.
Class
|
Structure
|
1. Class is user defined data type. It's a way of binding data and functions together in one single unit. It is a collection of data members and member functions.
|
1. Structure contains logically related data items which can be of similar type or different type.
|
2. It allows data and functions to be hidden from external use.
|
2. In structure data is not hidden from external use.
|
3. In class all members are by default are private.
|
3. In structure all members by default are public.
|
4. In class object is created.
|
4. In structure structure_variable is created.
|
5. Syntax: class class_name { access specifier: declare data members; declare member functions; };
|
5. Syntax: structstructure_name { datatype variable1; datatype variable2; .. .. }structure_variable;
|
for e.g. class student { private: introll_no; char name[20]; public: void getdata(); void putdata(); };
|
for e.g. struct student { introll_no; char name[20]; }s;
|