1 #include<iostream> 2 using namespace std; 3 4 int main() 5 { 6 int a = 10; 7 8 /*int* p; 9 p = &a;*/ 10 int* p = &a; // 指针指向数据a的地址 11 12 cout << "sizeof (int *) = " << sizeof(int*) << endl; 13 cout << "sizeof (floaat *) = " << sizeof(float*) << endl; 14 cout << "sizeof (double *) = " << sizeof(double*) << endl; 15 cout << "sizeof (char *) = " << sizeof(char*) << endl; 16 // 在32位操作系统下,指针占4个字节空间大小,不管是什么数据类型 17 // 在64位操作系统下,指针占8个字节空间大小,不管是什么数据类型 18 return 0; 19 }
程序输出结果: