Overflowh Overflowh - 14 days ago 5
C++ Question

Pointer to a C++ structure

If I create a structure in C++ like this:

typedef struct node {
int item;
int occurrency;
};


I know that a structure is allocated in memory using successive spaces, but what is the name of the structure (
node
in this example)? A simple way to give a name to the structure?

Answer

node is the name of the type. You can have multiple objects of that type:

struct node {
  int item;
  int occurrency;
};
node a;
node b;

In this example, both a and b have the same type (==node), which means that they have the same layout in memory. There's both an a.item and a b.item.

Comments