指针数组与数组指针

//

#include <iostream>
using namespace std;


int main()
{
    int* h[10];
    cout << h << endl;
    int c[2][2] = { {1, 2}, {3, 4} };
    cout << c << endl;
    cout << *c << endl;
    cout << c[0] << endl;
    cout << c[0][0] << endl;
    *h = *c;
    cout << *h << endl;
    int b[1] = {10};
    *h = b;
    cout << *h << endl;
    cout << **h << endl;

    int(*p)[3];
    int a[3] = { 1, 2, 3 };
    //a表示数组首元素的首地址
    //&a表示数组的首地址
    //a和&a值相同但是意义不一样
    //cout << p << endl; 一定要对p进行初始化,不然就是野指针,程序报错
    cout << *a << endl;
    cout << a[1] << endl;
    p = &a;
    //p = a;//报错,左右两边数据类型不一致
    cout << p << endl;
    cout << *p << endl;
    cout << (p + 1) << endl;
    cout << *(p + 1) << endl;

    int d[3][3];
    int(*m)[3];
    m = d; 
    //m = &b;//报错,数据类型不一致
    return  0;
}

posted on 2020-09-10 10:46  张芙蓉  阅读(111)  评论(0编辑  收藏  举报

导航