The difference between a structure and a class is that, in a class, the member data or functions are private by default whereas, in a structure, they are public by default. The following segment
class Product { private: char name[10]; int price; public:void input(); { cin >> name; cin>>price; } };
is equivalent to
class Product { char name[10]; int price; public: void input() { cin>> name; cin>>price; } };
since in a class, the members are private by default.
In a structure, the members are public by default. Hence if Product is declared as a structure, the keyword private has to be mentioned in case the data is private.
However, the word public need not be mentioned before the function input() since it is public by default. This is illustrated below:
struct Product { private: char name[10]; char colour[5]; void input() { cin>>name; cin>>colour; } }