CPP Programming
About Lesson

Limitations of C Structures:

  • C does not allow struct data type to be treated like built-in types.

Example:

struct complex

{

float x;

float y;                              

};

struct complex c1,c2,c3;

the variables c1,c2,c3 can be assigned values using dot operator but adding or subtracting one from another is not possible.

c3=c1+c2 is not valid in C

  • C structure does not permit data hiding. Structure members can be directly accessed by the structure variables by any function

Extensions to Structures:

In C++, a structure can have both variables and functions as members.  It can also declare its members as ‘private’ so that they can’t be accessed directly by the external functions.

The struct keyword can be omitted in the declaration of structure variables.

For example, we can declare the variable A of structure student like below:

student A;  //Possible in C++, but not in C

You cannot copy content of this page