当我执行以下代码时:
int main()
{
char **temp;
printf("Size of **temp %d", sizeof(**temp));
printf("Size of *temp %d", sizeof(*temp));
printf("Size of temp %d", sizeof(temp));
return 0;
}
我得到:
Size of **temp 1
Size of *temp 8
Size of temp 8
我不明白的是
char
指针的大小是8
吗?它与机器无关吗?
最佳答案
在最初的问题中,您没有调用sizeof
。 duskwuff为您修复了该问题。
产生的输出是:
Size of **temp 1
Size of *temp 8
Size of temp 8
原因:
在64位体系结构上,指针为8字节(无论指针指向什么)
**temp is of type char ==> 1 byte
*temp is of type pointer-to-char ==> 8 bytes
temp is of type pointer-to-pointer-to-char ==> 8 bytes
关于c - sizeof char **指针是否取决于机器的体系结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10094137/