C++ struct vs class

This is an example to show the similarity between a struct and a class

  #include <iostream>using namespace std;

int main()


struct employee

{char *name;

int age;

double salary;


employee e257 = {”raja“,25,23519.78};

cout<< e257.name<<”\t”<<e257.age

<<”\t”<<e257.salary <<endl;

class Employee { public:      char *name;
     int age;double salary; };

Employee E257 = {”raja”,25,23519.78};

cout<< E257.name<<”\t”<<E257.age

<<”\t”<<E257.salary <<endl;

1) All members of a struct are public by default 
2) All members of a class are private by default 
3) For a class member to be public, it has be 
declared public with the keyword "public".  
Advantage of using classes 
1) Member variables are private and protected. 
2) Constructors functions(declared public) can be 
used  to initialize and modify values of that private variables. 
See this page for Constructors:  Constructors & Destructors </pre
 Download here.struct.doc