//指针未初始化
int main()
{
int* p;
*p = 10;
return 0;
}
//指针越界访问
int main()
{
int arr[10] = { 0 };
int* p = arr;
int i = 0;
for (i = 0; i <= 10; i++)
{
*p = -1;
p++;
}
return 0;
}
//指针指向空间被释放
int* test()
{
int a = 10;
return &a;
}
int main()
{
int* p = test();
printf("%d\n", *p);
return 0;
}
//二级指针
int main()
{
int a = 10;
int* p = a;
int* *pp = &p;//第一个*表明指针类型,第二个*提示我们这是指针
return 0;
}
//指针数组模拟实现二维数组
int main()
{
int arr1[] = { 1, 2, 3,4 , 5 };
int arr2[] = { 2,3,4,5,6 };
int arr3[] = { 3,4,5,6,7 };
int* arr[] = { arr1, arr2,arr3 };
int i = 0;
for (i = 0; i < 3; i++)
{
int j = 0;
for (j = 0; j < 5; j++)
{
printf("%d ", arr[i][j]);
}
printf("\n");
}
return 0;
}