followin代码的输出显示4,为什么它显示4作为输出?
问题描述:
#include<stdio.h>
#include<conio.h>
int main()
{
void *p;
printf("%d",sizeof(p));
getch();
return 0;
}
答
正如我在答复中问到的那样:p
是一个指针:系统中指针的大小为32位.因此,sizeof(p)
返回4-四个字节为32位. p指向什么(void,char,int或nowhere)无关紧要:指针的大小在系统中始终为4个字节.
As I said when you asked this in a reply:p
is a pointer: the size of a pointer in your system is 32 bits. Thereforesizeof(p)
returns 4 - four bytes makes 32 bits. It doesn''t matter what p points to (void, char, int, or nowhere): the size of the pointer is always 4 bytes in your system.
指针的大小将通常可能是4个字节,尽管在64位计算机中可能有所不同(8个字节而不是4个字节).
Size of a pointer will usually tend to be 4 bytes, although it may be different in a 64bit machine (8 bytes instead of 4).