[cpp] view plain copy
 
 从sizeof 数组和指针看,数组和指针是不同的从sizeof 数组和指针看,数组和指针是不同的
  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. }  
从sizeof 数组和指针看,数组和指针是不同的


结果输出:

 

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

 

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

相关文章:

  • 2021-06-27
  • 2021-07-15
猜你喜欢
  • 2021-10-12
  • 2021-08-27
  • 2022-12-23
  • 2022-12-23
  • 2021-04-10
  • 2021-12-01
  • 2021-11-18
相关资源
相似解决方案