Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

ขนาดของ Void Pointer ใน C/C++

ขนาดของ void pointer ขึ้นอยู่กับระบบ (system architecture)

  • 16-bit system: 2 bytes
  • 32-bit system: 4 bytes
  • 64-bit system: 8 bytes

ตัวอย่างหาขนาด void pointer

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

ผลลัพธ์ (บนระบบ 64-bit)

The size of pointer value: 8

ใช้ sizeof() วัดขนาด pointer void*