#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int* test()
{
int a = 10;
return &a;
}
int main()
{
int* p = test();
*p = 20;
printf("%d", *p);
//非法,a是局部变量,出了test后被释放
//指针类型决定了指针进行解引用时能访问的空间大小
//int* p;*p能访问4个字节
//char* p;*p能够访问1个字节
//double*p;*p能访问8个字节
//指针类型决定了:指针走一步走多远(指针的步长)
return 0;
}
指针变量
原创wx643552926d6ae ©著作权
©著作权归作者所有:来自51CTO博客作者wx643552926d6ae的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
C语言指针的基本认识
C语言指针的基本认识
指针变量 指针类型 指针数组 -
指针变量
指针变量定义的一般形式:类型说明符 (*指针变量名)();函数指针变量是个变量,所有也可以作为
指针变量 #include 微信公众号