1.指针的定义和用法
2.指针所占内存空间
总结:所有指针类型在32位操作系统下是4个字节
3.空指针和野指针
空指针访问内存为0~255时,其为系统占用的内存,不允许用户访问
const 修饰指针
4.指针和数组
#include<iostream> using namespace std; int main() { int arr[] = { 12,32,56,78,98,12,56,57,89,21 }; int* p = arr; cout << *p << endl; for (int i = 0; i < 10; i++) { cout << *p << endl; p++; } return 0; }
5.指针和函数
#include<iostream> using namespace std; void swapone(int a, int b) { int temp = a; a = b; b = temp; cout << "a=" << a << endl; cout << "b=" << b << endl; } void swaptwo(int *a, int *b) { int temp = *a; *a = *b; *b = temp; cout << "a=" << *a << endl; cout << "b=" << *b << endl; } int main() { int a = 10; int b = 20; swapone(a, b); swaptwo(&a, &b); return 0; }
6.指针,数组,函数综合