August 1st, 2013, 06:01 PM
Need help with conversion of a pointer
I need help understanding an expression(and the precedence of the compiler's actions when evaluating the expression), involving conversion of a pointer.
My declarations are such:
Why is the "*" operand in the inner brackets located after the word "BookPtr" and not before as such: *(*BookPtr)
struct Book /*a simple struct*/
Book *array; /*an array of pointers, each pointing to a Book struct*/
"pbook": is any member of the array above, i use it as function arguments by-name-- pbook1=array, pbook2=array etc'
typedef Book *BookPtr; /*BookPtr is a pointer to a Book struct*/
(*ppbook)----> is a pointer to (*pbook), so it's actually a double pointer
The expression in question:
BookPtr pbook1= *(BookPtr *)ppbook1;
BookPtr pbook2= *(BookPtr *)ppbook2;
But most importantly- what does it mean when the "*" is ALSO LOCATED OUTSIDE THE BRACKETS? in this case, is it true that the conversion takes place first and then the "*" is applied? And when it IS applied what does it mean about the whole expression?
Last edited by C learner; August 2nd, 2013 at 03:02 AM.
Reason: Conversion of a pointer
August 1st, 2013, 09:20 PM
Because it is not correct.
You can use 'BookPtr' as a pointer;
typedef Book * BookPtr;
Book *array; is same as BookPtr array;
Pointers - C++ Documents
Tutorial: Pointers in C and C++