开发者

What is the equivalent syntax of this line of code(myMovie->pMovieTitle->pValue) using the * and . operators?

struct Values {
char *pValue;   //character string
int nBytes; //amount of bytes
};

struct Movie {
Values *pMovieTitle;    //Name of Movie
};

Movie *myMovie;

1) What is the equivalent syntax of this line of code using the * and . operators?

myMovie->pMovieTitle->pValue;

I tried

(*myMovie).pMovieTitle->pValue

which works, however

(*myMovie).(*pMovieTitle).pValue

Doesn't work.

2) Why are there two arrow operators when there are three pointers? myMovie, pMovieTitle and pValue are all pointers.

For example there are two arrow operators for this line of code:

myMovie->pMovieTitle->pValue;

and there are two arrow operators开发者_运维技巧 for this line of code:

myMovie->pMovieTitle->nBytes;

Even though pValue is a pointer and nBytes is not.


  1. Your second attempt should be (*(*myMovie).pMovieTitle).pvalue; you can't dereference a struct member, only the value returned after accessing said member.

  2. The fact that pValue is a pointer is irrelevant; -> is used when the object on the left is a struct pointer, regardless of the type of the member named on the right.


  1. (*((*myMovie).pMovieTitle)).pValue

  2. It doesn't matter if pValue is a pointer you aren't dereferencing it anyway.


Because I think you have to do something like :

 (*((*myMovie).pMovieTitle)).pValue 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜