I have always despised the C questions in a row of expressions, ++. Today, I accidentally saw one, but I didn't pay attention to it. I was very lucky when I did it. Alas, it seems that my basic things are still a little weak.
The questions are as follows:
Pointer operation:
Int * P1, * P2;
Int value;
P1 = (int x) 0x500;
P2 = (int x) 0x508;
Value = P2-P1;
Q: What is the value of value?
The answer 2 provided on the Internet is strange for a long time. In fact, value = P2-P1 is equivalent to (508-500)/sizeof (INT ). In this case, the answer is uncertain. On Windows/TC, the value is 4, and on AIX it is 2, the reason is that the size of int in different compilers is different from that in OS.
The question is easy to shake. In fact, it is to let you understand the addition and subtraction operations of the address. For example, the following forms are very common:
Int A [5];
Int I;
Int * P1 =;
For (I = 0; I <5; I ++)
{
* P1 = I;
P1 ++;
}