从sizeof 数组和指针看,数组和指针是不同的

[cpp] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. #include<iostream>  
  2. using namespace std;  
  3. void fun(int *P)  
  4. {  
  5.     cout<<"在函数中"<<sizeof(P)<<endl;  
  6. }  
  7. int main()  
  8. {  
  9.     int A[10];  
  10.     int* B=new int[10];  
  11.     cout<<"数组名"<<sizeof(A)<<endl;  
  12.     cout<<"指针"<<sizeof(B)<<endl;  
  13.     fun(A);  
  14. }  


结果输出:

 

数组名40
指针4
在函数中4

 

另外数组是地址常量,指针是地址变量

posted @ 2017-04-06 18:02  zhanghonglang  阅读(358)  评论(0)    收藏  举报