C/C++ 中 void 指针的大小是多少?


void 指针的大小因系统而异。如果系统是 16 位的,则 void 指针的大小为 2 个字节。如果系统是 32 位的,则 void 指针的大小为 4 个字节。如果系统是 64 位的,则 void 指针的大小为 8 个字节。

这里有一个 C 语言中查找 void 指针大小的示例:

示例

 在线演示

#include <stdio.h>
int main() {
   void *ptr;
   printf("The size of pointer value : %d", sizeof(ptr));
   return 0;
}

输出

The size of pointer value : 8

在上述示例中,创建了一个 void 类型指针变量,并通过使用 sizeof() 函数,找出了 void 指针的大小。

void *ptr;
printf("The size of pointer value : %d", sizeof(ptr));

更新时间:2020 年 6 月 26 日

7 千+ 浏览

开启你的职业生涯

完成课程认证

开始
广告