当前位置:网站首页>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 .
边栏推荐
- 云计算笔记part.1——系统管理
- How many types of rain do you know?
- Sequential linear table - practice in class
- Concurrent programming, do you really understand?
- There is a 'single quotation mark' problem in the string when Oracle inserts data
- Array method added in ES6
- Basic concept and essence of Architecture
- English translation Portuguese - batch English conversion Portuguese - free translation and conversion of various languages
- Leetcode Day1 score ranking
- String中常用的API
猜你喜欢

KubeEdge发布云原生边缘计算威胁模型及安全防护技术白皮书

河北邯郸:拓展基层就业空间 助力高校毕业生就业

English translation Arabic - batch English translation Arabic tools free of charge

Function fitting based on MATLAB

Saltstack advanced

Edge detection and connection of image segmentation realized by MATLAB

There is a 'single quotation mark' problem in the string when Oracle inserts data

Source insight project import and use tutorial

数字图像理论知识(一)(个人浅析)

Can China make a breakthrough in the future development of the meta universe and occupy the highland?
随机推荐
[C language] guessing numbers game [function]
In the second half of 2022, the system integration project management engineer certification starts on August 20
Question bank and answers of the latest national fire-fighting facility operators (intermediate fire-fighting facility operators) in 2022
The cloud native programming challenge is hot, with 510000 bonus waiting for you to challenge!
基于 MinIO 对象存储保障 Rancher 数据
MySQL命令语句(个人总结)
Rand function generates pseudo-random numbers
XOR operation and its usage
[C language] shutdown game [loop and switch statement]
Prometheus deployment
leetcode day1 分数排名
Servlet learning notes
[C language] Gobang game [array and function]
[C language] scanf format input and modifier summary
Application skills of programming rising and falling edge instructions of botu 1200/1500plc (bool array)
党员故事|李青艾用漫画带动农民增收致富
[C language] step jumping problem [recursion]
English translation Portuguese - batch English conversion Portuguese - free translation and conversion of various languages
How many types of rain do you know?
Using Lex (Flex) to generate lexical analyzer of PL language