zoukankan      html  css  js  c++  java
  • void f(int(&p)[3]){} 和void f(int(*p)[3]){}的差别

    #include<iostream>
    using namespace std;

    void f(int(&p)[3]){
        
        cout<<p[0]<<endl;
        cout<<p[2]<<endl;
    }


    int main(){
        int a1[3]={1,2,3};
        cout<<a1<<endl;
        cout<<&a1<<endl;
        f(a1);
    }


    编译后输出:

    0xbfbb8eb4
    0xbfbb8eb4
    1
    3


    #include<iostream>
    using namespace std;

    void f(int(*p)[3]){
        
        cout<<p[0]<<endl;
        cout<<p[2]<<endl;
    }


    int main(){
        int a1[3]={1,2,3};
        cout<<a1<<endl;
        cout<<&a1<<endl;
        f(&a1);
    }


    编译后输出:

    0xbff21e84
    0xbff21e84
    0xbff21e84
    0xbff21e9c


    由此比較能够看出,
    void f(int(*p)[3]){}是个函数指针数组,指针数组属于二级指针


  • 相关阅读:
    9.19题解
    9.18题解
    改码风
    找到了几个好的网站
    题目链接
    二分上机训练题解
    二分例题简单说明
    贪心上机训练题解
    贪心算法例题简单说明
    Johnson法则证明
  • 原文地址:https://www.cnblogs.com/cxchanpin/p/7236029.html
Copyright © 2011-2022 走看看