Data Structures, would appreciate an example of something in particular. (See post for details)

The following is from the documentation of the site we are on right now under:
Pointers to Structures. http://www.cplusplus.com/doc/tutorial/structures/

"*pmovie.title

which is equivalent to:

*(pmovie.title)

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).
"

I need a simple coding example of this as i have tried to use those two lines of code to do what it describes and i have tried for hours to figure out how to use them.


I understand that i am probably overthinking or missing something simple but a simple example using "*pmovie.title or *(pmovie.title)" to access the value pointed by a hypothetical pointer member called title of the structure object pmovie would be so extremely helpful!

I have literally been trying to figure it out the whole night. (It is 5:30 am now)

If you can help me thank you so much!




Last edited on
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)."

I need a simple coding example of this as i have tried to use those two lines of code to do what it describes and i have tried for hours to figure out how to use them.


Because pmovie is a pointer, you cannot use the dot notation with it unless the forms introduced prior to these are used as well. These forms will never be valid when pmovie is a pointer.

You can ignore the "And that..." sentence. It is very awkwardly worded. The one to pay attention to is:

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 (the invalid expressions:)


I added the last bolded bit for clarity.
Last edited on
1
2
3
4
5
6
7
struct test{
  int* pointer;  //creates a pointer to int which is a member of the struct
}obj;

int g;
obj.pointer=&g;
*obj.pointer=12;  //sets the value of g to 12 


HTH,
Aceix.
Thank you both very much. Thank you aceix and thank you cire!

Marked as solved. :)
Topic archived. No new replies allowed.