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;

Get SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.