c++中的有趣指针

#include <iostream>
using namespace std;

int test(int a,int b)
{
	return a+b;
}

int main()
{
	int a=test(96,2); //调用函数test
	int *ip;    //声明一个指针
	ip=&a;   //吧a的地址存在放指针中

	cout << &a << endl; //打印a变量的地址
	cout<<ip<<endl;//打印指针
	cout<<a<<endl;//a的值
	cout<<*ip<<endl;//从指针中取值
    return 0;
}

//用编辑器编译一下结果为

0x7ffc85854858
0x7ffc85854858
98
98

猜你喜欢

转载自blog.csdn.net/document_ljt/article/details/83818086