O'Reilly logo

SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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;

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required