我正在和一位对低级语言不熟悉的人以及今天的手动内存管理进行交流,并尽我所能解释指针。递归指针
然后,他想出了:
#include <stdio.h>
int main()
{
int v = 0;
void* vp = &v;
int i = 0;
for(; i < 10; ++i)
{
printf("vp: %p, &vp: %p\n", vp, &vp);
vp = &vp;
}
}
的这是输出:
vp: 0xbfd29bf8, &vp: 0xbfd29bf4
vp: 0xbfd29bf4, &vp: 0xbfd29bf4
vp: 0xbfd29bf4, &vp: 0xbfd29bf4
vp: 0xbfd29bf4, &vp: 0xbfd29bf4
vp: 0xbfd29bf4, &vp: 0xbfd29bf4
vp: 0xbfd29bf4, &vp: 0xbfd29bf4
vp: 0xbfd29bf4, &vp: 0xbfd29bf4
vp: 0xbfd29bf4, &vp: 0xbfd29bf4
vp: 0xbfd29bf4, &vp: 0xbfd29bf4
vp: 0xbfd29bf4, &vp: 0xbfd29bf4
这是没有意义的他作为副总裁应该= &副总裁!我很惭愧地说,我不知道这里发生了什么事。所以,这里发生了什么?
Hmn,我没有意识到&vp腐烂vp?为什么不在printf中这样做? –
@ KimSun-wu:它不会衰退。 –
'&vp'不衰减为'vp'。该分配的作用是将'vp'的地址存储在'vp'(属于'vp'的RAM单元)中。所以,在地址0xbfd29bf4你有值0xbfd29bf4。 –