指针可以理解为定义一种地址类型
指针可以理解为定义一种地址类型
#include <iostream>
using namespace std;
int main()
{
int a = 10;
float b = 9.7f;
int c = 20;
// & 取得一个变量的内存地址
//cout << &a << endl; // 0093F748
//cout << &b << endl; // 0093F73C
// * 从内存地址所对应的内存处 取得数据
//cout << *(&a) << endl; // 10
//cout << a << endl; // 10
// error: cout << *a << endl;
int* pa = &a;
float* pb = &b;
//cout << pa << endl; // 0079F722
//cout << pb << endl; // 0079F71C
//cout << *pa << endl; // 10
//cout << *pb << endl; // 9.7
//int* p;
//p = pa;
//cout << *p << endl; // 10
//cout << *pa << endl; // 10
//*pa = 100;
//cout << a << " " << *pa << endl; // 100 100
//*p = 300;
//cout << a << " " << *pa << " " << *p << endl; // 300 300 300
int* p1;
int* p2;
cout << p1 << " " << p2 << endl; // 报错:使用未初始化的内存
return 0;
}
int main (){
int *p;
p=pa;
int *p1;
int *p2;
cout<<p1<<" "<<p2<<endl;
}