当前位置:网站首页>9. Pointer of C language (2) wild pointer, what is wild pointer, and the disadvantages of wild pointer
9. Pointer of C language (2) wild pointer, what is wild pointer, and the disadvantages of wild pointer
2022-07-28 20:05:00 【A programmer who loves playing badminton】
This article is the... Of the pointer series 2 piece , If it feels good , You can follow and collect , It will be updated continuously in the future
The wild pointer is The position of the pointer is unknown ( Random 、 incorrect 、 There is no definite limit to ) If the pointer variable is not initialized when it is defined , Its value is random , The value of a variable is the address of another variable , It means that the pointer points to a variable whose address is uncertain , To dereference is to access an uncertain address , So the result is unknowable .
We watch through code
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
int *p; // Defining pointer variables p
//*p Representative to p The content of the address is the variable
int i = 5;
*p =i;// Wild pointer
}
When we define variables , The operating system assigns addresses to variables , There are two variables in the code , Pointer to the variable p And integer variables i
If we don't assign values to variables , The variable will be randomly assigned a value , Also called garbage value .
Usually , We are defining pointer variables p after , It should be assigned a value , such as p = &i; such p It points to i
But in the code above , We didn't give p assignment ,p The address stored in it is a random garbage value
Through this garbage value address , That is, through *p, We found an unknown variable , If this unknown variable is modified at this time , We may cause the computer to crash , We may have changed important resources . Such behavior is not allowed
In some editors, such as VC6.0 There may be a mistake , There will be no error in some editors
summary
Wild pointer is a dangerous behavior , We must be careful when defining pointer variables , Remember to assign a correct value to the pointer variable .
边栏推荐
- Application skills of programming rising and falling edge instructions of botu 1200/1500plc (bool array)
- Question bank and answers of the latest national fire-fighting facility operators (intermediate fire-fighting facility operators) in 2022
- [C language] initial C language reflection and summary
- [C language] Gobang game [array and function]
- Cdga | how can the industrial Internet industry do a good job in data governance?
- 4. Const and difine and the problem of initializing arrays with const and define
- C language implementation of strncpy
- Leetcode day3 find duplicate email addresses
- 时间转日期的sql语句应该怎么写?
- 2、 Relationship between software operation and memory
猜你喜欢
一文读懂如何部署具有外部数据库的高可用 K3s
NetCoreAPI操作Excel表格
Basic knowledge of communication network 01
CDGA|工业互联网行业怎么做好数据治理?
11. Learn MySQL union operator
Implementation of strstr in C language
Integration and implementation of login click graphic verification code in personal blog system
[C language] header file of complex number four operations and complex number operations
基于 MinIO 对象存储保障 Rancher 数据
Prometheus deployment
随机推荐
How many types of rain do you know?
Intermediate soft test (system integration project management engineer) high frequency test site
English translation Italian - batch English translation Italian tools free of charge
[NPP installation plug-in]
C language implementation of strncpy
editor.md中markdown编辑器的实现
Deploy ZABBIX automatically with saltstack
JVM(二十四) -- 性能监控与调优(五) -- 分析GC日志
[网络]跨区域网络的通信学习路由表的工作原理
Basic concept and essence of Architecture
Token verification program index.php when configuring wechat official account server
Question bank and answers of the latest national fire-fighting facility operators (intermediate fire-fighting facility operators) in 2022
Implementation of strstr in C language
Implementation of strcat in C language
Basic knowledge of C language
Getting started with enterprise distributed crawler framework
Sequential linear table - practice in class
How navicate modifies the database name
Codeignier framework implements restful API interface programming
English translation Arabic - batch English translation Arabic tools free of charge