Structures on the Stack

You can declare a variable of a structure type on the stack. For instance:

aTapeElement TapeElement;

But how do you initialize it? This is where the C++ member selection (.) operator comes in. It allows you to get or set the member variable values:

TapeElement.Operator = '+';
TapeElement.Operand = 234;
char Operator = TapeElement.Operator;

You can see that a well-chosen structure variable name makes this read more clearly.

It is also possible to create arrays of structures:

aTapeElement TapeElement[20];

This enables you to select member variables from any element:

TapeElement[5].Operator = '+';
TapeElement[5].Operand = 234;

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.25.128