c++中關於變量,引用,指針的簡單轉換

#include "stdafx.h"
#include <iostream>

int _tmain(int argc, _TCHAR* argv[])
{
	using namespace std;
	int rats=101;
	int &rodents=rats;//rodents是一個引用

	cout << "rats=" << rats;//101
	cout << ",rodents="<<rodents<<endl;//101

	int *prats=&rats;//prats是一個指針
	cout << "&rats=" << &rats;//內存地址
	cout << ",prats=" << prats;//內存地址
	cout << ",*prats=" << *prats;//101

	int a;
	cin >> a;

	return 0;
}


左邊是引用,右邊是變量

左邊是指針,右邊是引用

同理可以反向

左邊是引用,右邊指針

左邊是變量,右邊是引用

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章