|
Create a variable of a structure type the way you would create any variable: write the type followed by the variable name. For example, statements
PairOfInts p; Cell c;create a variable p of type PairOfInts and a variable c of type Cell.
Structures such as p and c above are stored in the frame of the current function. To allocate a structure in the heap, create a pointer variable:
Cell* p;
Notice that p is not yet initialized, and contains
a junk address.
Now, initialize p to point to newly allocated memory in the heap.
p = new Cell;
|