当前位置:网站首页>Wild pointer, null pointer, invalid pointer
Wild pointer, null pointer, invalid pointer
2022-07-24 07:14:00 【Zhangshufen~】
1. Wild pointer and null pointer
Put these two together , Because there is really no important knowledge point , Let's have a look first .
int main()
{
int *p;
int *p1=nullptr;
return 0;
}The pointer p For the wild pointer , That is, when defining a pointer, it is not initialized to nullptr, Then this pointer will point to a random address , This is the wild pointer , Wild pointers are very dangerous .
p1 Initialize to null when we define ,p1 Is a null pointer .
Notice that I'm using nullptr, No NULL,nullptr stay C++ Is a keyword used to initialize or assign a null pointer , Why not NULL Well ? Let's talk about it briefly , Later in this column, there will be a special article to introduce C++ in nullptr.
stay C In the language compiler ,NULL For the definition of #define NULL 0 perhaps #define NULL (void*)0;NULL Is a literal constant defined by a macro 0 Or a typeless pointer 0 Constant , Then this situation sometimes leads to ambiguity , There is no example here , Later articles can be read carefully , To solve this situation , stay C11 Medium standard medium , In consideration of compatibility , Literal constants 0 The ambiguity of has not been eliminated , But the standard still gives a new answer to ambiguity , Namely nullptr( A so-called “ Pointer null type ” The constant ).
2. Invalid pointer
The failure pointer is a key point of this chapter , So what is an invalid pointer ? Let's give an example of :
int main()
{
int *r=(int *)malloc(sizeof(int));
*r=100;
free(r);
边栏推荐
- C language from entry to soil function
- 第二部分—C语言提高篇_1. C语言概述
- 论文阅读:HarDNet: A Low Memory Traffic Network
- 【时序逻辑电路】——寄存器
- Talk about your thoughts about the future
- Don't care too much about what others think of you
- 一首伟大的赞歌
- QoS quality of service three DiffServ Model message marking and PHB
- 【行测】图形找规律类题目
- Prompt for garbled code when CHM file is opened
猜你喜欢

Redis sentinel mechanism

传统电商红利消失,怎么进军新型社交电商?

tensorflow scatter_ Nd function

Unity中使用深度和法线纹理

Ue4/5 cannot open the file "xxx.generated.h" (cannot open file xxx.generated.h) solution summary

C语言中extern,static, register,volatile 关键字的作用;保姆级教学!

Paper reading: hardnet: a low memory traffic network

【时序逻辑电路】——寄存器

Penetration learning - SQL injection - shooting range - installation and bypass experiment of safety dog (it will be updated later)

周杰伦直播超654万人观看,总互动量破4.5亿,助力快手再破纪录
随机推荐
开发系统选择路线
Chinese manufacturers may catch up with the humanoid robot Optimus "Optimus Prime", which has been highly hyped by musk
Paper reading: hardnet: a low memory traffic network
Ue4/5 cannot open the file "xxx.generated.h" (cannot open file xxx.generated.h) solution summary
重磅直播 | ORB-SLAM3系列代码讲解地图点(专题二)
被马斯克热炒的人形机器人Optimus“擎天柱“,中国厂商或后来居上
django.db.utils.OperationalError: (2002, “Can‘t connect to local MySQL server through socket ‘/var/r
B. Also Try Minecraft
Wix path with spaces
第二部分—C语言提高篇_1. C语言概述
第一部分—C语言基础篇_11. 综合项目-贪吃蛇
MySQL automatic generation creation time and update time
C language to achieve three chess? Gobang? No, it's n-chess
单点登录的三种实现方式
变量和数据类型(03)
第二部分—C语言提高篇_2. 内存分区
【时序逻辑电路】——寄存器
找工作备忘
C语言中extern,static, register,volatile 关键字的作用;保姆级教学!
Redis 哨兵机制