I read this in a book.
I tested the code and found out that it's sizeof integer multiplied by p. Can you some explain the precedence order of this?Code:apple = sizeof (int) * p;
thanks alot.
Printable View
I read this in a book.
I tested the code and found out that it's sizeof integer multiplied by p. Can you some explain the precedence order of this?Code:apple = sizeof (int) * p;
thanks alot.
What's confusing? All you are doing is multiplying the size of an integer by the value of p. There's no precedence order confusion here. What else could it possibly be? All you are doing is taking two things, multiplying them, and assigning that value some place.
Quzah.
sizeof has higher precedence than multiplication operator.
So the exp is equivalent to
apple = (sizeof(int)) * p;
Guess what will be the value of :
apple = sizeof p * p; // don't forget to init p to some vale
:D
It doesn't matter in what order multiplication is done in. Why the confusion?
OP is probably thinking: apple = sizeof (int) * p as
apple = sizeof( (int) *p); // say p is pointer to say (char)
which you need to know precedence.
If I'm not wrong, is it from Expert C Programming book?