055.指针-指针的定义和使用

#include <iostream>
using namespace std;
int main()
{

    //1.定义指针
    int a = 10;
    //指针定义的语法:数据类型*指针变量名;
    int* p;
    //让指针记录变量a的地址
    p = &a;
    cout << "a的地址为:\t" << &a << endl;
    cout << "指针P为:\t" << p << endl;



    //2.使用指针
    //可以通过解引用的方式来找到指针指向的内存地址
    //指针前加*代表解引用,找到指针指向的内存中的数据
    *p = 1000;
    cout << "a=" << a << endl;
    cout << "*p" << *p << endl;

    system("pause");
    return 0;
}

 

posted @ 2021-09-04 14:11  梦之心  阅读(216)  评论(0编辑  收藏  举报