当前位置:网站首页>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 .
边栏推荐
- 数字滤波器设计——Matlab
- [C language] initial C language reflection and summary
- Implementation of memcpy in C language
- [C language] shutdown game [loop and switch statement]
- Implementation of strstr in C language
- Redis notes
- Array method added in ES6
- Leetcode Day2 consecutive numbers
- In the second half of 2022, the system integration project management engineer certification starts on August 20
- Leetcode day2 连续出现的数字
猜你喜欢
![[C language] random number generation and `include < time. H > 'learning](/img/bb/3e47bf2e3b25653d9048884d65cda3.png)
[C language] random number generation and `include < time. H > 'learning

4. Const and difine and the problem of initializing arrays with const and define

ssm中项目异常处理

Stories of Party members | Li qingai uses cartoons to drive farmers to increase income and become rich

English Translation Spanish - batch English Translation Spanish tools free of charge

NetCoreAPI操作Excel表格

Implementation of markdown editor in editor.md

XOR operation and its usage

Longest Palindromic Substring

Deploy ZABBIX automatically with saltstack
随机推荐
KubeEdge发布云原生边缘计算威胁模型及安全防护技术白皮书
Overcome the "fear of looking at teeth", and we use technology to change the industry
Hebei: stabilizing grain and expanding beans to help grain and oil production improve quality and efficiency
High beam software has obtained Alibaba cloud product ecological integration certification, and is working with Alibaba cloud to build new cooperation
Common modules of saltstack
C language implementation of strncpy
Using Lex (Flex) to generate lexical analyzer of PL language
Labelme (I)
ssm中项目异常处理
Handan, Hebei: expand grassroots employment space and help college graduates obtain employment
Prometheus deployment
English translation Portuguese - batch English conversion Portuguese - free translation and conversion of various languages
Saltstack advanced
Application skills of programming rising and falling edge instructions of botu 1200/1500plc (bool array)
通信网络基础知识01
Implementation of memcpy in C language
Machine learning -- model evaluation, selection and verification
Integration and implementation of login click graphic verification code in personal blog system
The results of the second quarter online moving people selection of "China Internet · moving 2022" were announced
English translation Italian - batch English translation Italian tools free of charge