Int x = (int (*) [7]) 256-(int (*) [7]) 0;
After running, the x result is 9. I don't know how to explain it? # Include <stdio. h>
Typedef int (* p) [7]; // The result here is the same as that in your field, but you are given an empty name type.
Typedef p PA;
Int main ()
{
Int x = (PA) 256-(PA) 0;
Printf ("x = % d/n", x );
Return 0;
}
First of all, you do not understand why your program outputs 9,
To be honest, you just don't really understand the pointer. Let's analyze it first.
(*) [7]: indicates a pointer pointing to an array of 7 elements,
Int...: indicates that these elements are of the int type.
So:
(Int (*) [7]): indicates a pointer to an array of seven int elements.
Then, the subtraction between the (PA) 256 type and the (PA) 0 type is the subtraction between the pointer and the pointer,
The offset between pointer and pointer is related to type. The type here is
(Int (*) [7]) type, which is expressed by PA and easier to understand! Haha!
How big is PA ?? 28? Haha! No, it's 4
PA is a pointer pointing to an array.
It's just the type of PA, but it's another type. Oh, isn't it a bit dizzy !!
So,
(PA) 256 is forced to convert 256 into a pointer pointing to [7,
What is the size of [7? 28 !!! Oh, that's right. The type is int.
Of course !!!
So
256/28-256/0 ====== ??? How much? 9
This is what it looks like!
You can give it a try. Change [7] to 8. Try it. Can you guess it now? I think it should be 8.
Not necessarily. Try it !!! To be honest, I did not understand :(