Structures and Unions in C++

struct sample
{
      int num;
      char str[10];
};

union data
{
      int id;
      float val;
};

Unlike C,C++ does not need the keywords struct,union while defining variables.See below
sample s1;
data d1;

Structures and unions of C++ can contain as their elements not only various data types but also functions.

No comments:

Post a Comment