|
|
|
|
C++ Programming Tutorials Control Structures Compound Data Types Object Oriented Programming Advanced Concepts C++ Standard Library
Soft Skills
|
C++ Programming TutorialsPointers to structures
Here amovie is an object of structure type movies_t, and pmovie is a pointer to point to objects of structure type movies_t. So, the following code would also be valid:
The value of the pointer pmovie would be assigned to a
reference to the object amovie (its memory address).
The previous code includes an important introduction: the arrow operator (->). This is a dereference operator that is used exclusively with pointers to objects with members. This operator serves to access a member of an object to which we have a reference. In the example we used:
Which is for all purposes equivalent to:
Both expressions pmovie->title and (*pmovie).title are valid and both mean that we are evaluating the member title of the data structure pointed by a pointer called pmovie. It must be clearly differentiated from:
which is equivalent to:
And that would access the value pointed by a hypothetical pointer member called title of the structure object pmovie (which in this case would not be a pointer). The following panel summarizes possible combinations of pointers and structure members:
Nesting structures
After the previous declaration we could use any of the following expressions:
(where, by the way, the last two expressions refer to the same member). NEXT >>
Other Data Types
Check C Interview Questions for more C Interview Questions with Answers. |