32位环境下,int *p=new int[10];请问sizeof(p)的值为()
A、4 B、10 C、40 D、8
正确答案为A,只是指针p占的空间,而不是40,。
因此写段代码测试一下:
- #include<iostream>
- using namespace std;
- void fun(int *P)
- {
- cout<<"在函数中"<<sizeof(P)<<endl;
- }
- int main()
- {
- int A[10];
- int* B=new int[10];
- cout<<"数组名"<<sizeof(A)<<endl;
- cout<<"指针"<<sizeof(B)<<endl;
- fun(A);
- }
结果输出:
数组名40
指针4
在函数中4
但是数组在作为函数参数传递过程中,会退化成指针。因此,函数内数组名的sizeof为4.