Structure - Difference between C and C++

 There some difference in the structure or Union between C and C++. In C a structure can contain only the data members. But in C++ they can have Function along with their data members.

 

In C++ when declaring the variable of type structure we no need to specify the keyword struct. Also it is not required to have the typedef in the structure declaration. But, in C you have to specify the struct keyword before declaring the variable of structure. Or, the Structure declaration should have the typedef.

 

struct st

{

            int memebr1;

            int memebr2;

};

 

int _tmain(int argc, _TCHAR* argv[])

{

            st var1;

            var1.memebr1 = 15;

}

 

The above code snippet is for C++. Note that there is no typedef for the st. Also note that there is no struct keyword when I am declaring the variable var1.