定义&使用:
#include<iostream>
using namespace std;
int main()
{
// 指针:即储存地址
int a = 10;
int* p; //定义语法:数据类型*指针变量名
p = &a; // &为取址符号
cout << "a的地址为:" << &a << endl;
cout << "指针p为:" << p << endl;
// 使用
*p = 1000; // 称为解引用,即相当于a
cout << "a=" << a << endl;
cout << "*p=" << *p << endl;
system("pause");
return 0;
}
内存:
#include<iostream>
using namespace std;
int main()
{
// 指针
int a = 10;
int* p = &a;
cout << "所占内存为" << sizeof(p) << endl;
// 等价于
cout << "所占内存为" << sizeof(int*) << endl;
system("pause");
return 0;
}