This paper makes a brief analysis of the pointer problem in the "in-depth comprehension of C language" in Coolshell.
#include <stdio.h>intMainvoid){ inta[5]; printf ("%x\n", a); printf ("%x\n", A +1); printf ("%x\n", &a); printf ("%x\n", &a +1); return 0;}
Suppose the address of a is: 0xbfe2e100, and the 32-bit machine, then what will the program output?
#1: The first printf statement should have no problem, that is bfe2e100
#2: The second printf statement you might think is bfe2e101. That's wrong, a+1, the compiler compiles A + 1*sizeof (int), and int is 4 bytes under 32 bits, so it's
Plus 4, which is bfe2e104. "A is a pointer to data of type int"
#3: The third printf statement may be your biggest headache, how do we know the address of a? I don't know? It's not bfe2e100. Wouldn't that be a a==&a? How is that?
Yes? To save your own? maybe a lot of people think that pointers and arrays are one thing, then you're wrong . if it is int *a, because A is a pointer, so &a is the address of the pointer, A and
&a No same . but this is an array ah a[], so &a is actually compiled into &a[0].
#4: The fourth printf statement is natural, that is bfe2e104. Or not, because &a is an array and is considered int (*) [5], so sizeof (a) is 5, which is
5*sizeof (int), also known as bfe2e114. "&a can be understood as a pointer to an int [5] type, i.e. A is an array type"
Reference:
In-depth understanding of C language: http://coolshell.cn/articles/5761.html