当前位置:网站首页>9. Pointer of C language (1) what is pointer and how to define pointer variables
9. Pointer of C language (1) what is pointer and how to define pointer variables
2022-07-28 20:05:00 【A programmer who loves playing badminton】
This article is the... Of the pointer series 1 piece , If it feels good , You can follow and collect , It will be updated continuously in the future
Pointer is C The soul of language
C Language can be used by pointer
Represents some complex data structures
Fast data transfer
Make the function return more than one value
Direct access to hardware
It can easily handle strings
Before learning the pointer , We need to understand the concept and relationship between address and pointer
Address : Refers to the number of memory unit , It's from 0 The starting nonnegative integer , In the computer , Byte is the basic unit of data storage , And it is also the smallest unit that the hardware can access , A byte is a number .
The pointer : The pointer is the address , The address is the pointer , It's a value , It's the number
Pointer to the variable : Is a variable for storing addresses , What we need to learn is pointer variables , Usually, when we describe, we will abbreviate pointer variables as pointers , Actually, they have different meanings
Let's learn how to define pointer variables through a simple example
#include <iostream>
#include <stdio.h>
using namespace std;
int main(int argc, char const *argv[])
{
int *p; //p It's the name of the variable ,int* Express p Variables are stored in int The address of a type variable
//int* p; Does not mean that a name is defined *p The variable of
//int* p; It should be understood that :p Is a variable name. ,p The data type of the variable is int* type
// So-called int* type , It's actually storing int Type of variable address
int i = 3;
p = &i;
/*
p Save the i The address of , therefore p Yes i
p No i,i Neither p, modify p The value of does not affect i Value , modify i The value of does not affect p
If a pointer variable points to a variable , be * Pointer variables are exactly the same as ordinary variables
Example :
If p It's a pointer variable , also p Stored ordinary variables i The address of
be p It points to the normal variable i
*p Is exactly the same as i
Or say : In all appearances *p All places can be replaced with i
*p That is to say p The content of the address is the variable
The pointer is the address , The address is the pointer , It's a value , It's the number
The address is the number of the memory unit
A pointer variable is a variable that holds an address
But be careful : Usually, when we describe, we will abbreviate pointer variables as pointers , Actually, they have different meanings
*/
// p=i; error, Because of the different types ,p Only store int The address of a type variable , Cannot be stored int Type value
int j;
j = *p; //*p Namely i
printf("i=%d,j=%d\n", i, j);
return 0;
}The output is i=3,j=3
summary : What we need to know is
1.int *p Its meaning is to define a pointer variable p,p It stores the address of the integer variable
p No i,i Neither p, modify p The value of does not affect i Value , modify i The value of does not affect p
2. Assignment statement p=&i; The meaning of &i Is to take i The address of , So this sentence expresses will i The address of is placed in the variable p in

We wrote p=&i After this sentence ,P It points to i Variable , At this time ,P The storage address is 1000H

3.*p Means to store in p The content of (1000H) Variable for address , In fact, it is 3
here *P Is equivalent to i
边栏推荐
- XOR operation and its usage
- 党员故事|李青艾用漫画带动农民增收致富
- Question bank and answers of the latest national fire-fighting facility operators (intermediate fire-fighting facility operators) in 2022
- C language implementation of strncpy
- Theoretical knowledge of digital image (I) (personal analysis)
- Deploy ZABBIX automatically with saltstack
- 云计算笔记part.2——应用管理
- [C language] Pointer advanced knowledge points
- 个人博克系统登录点击图形验证码的集成与实现
- Labelme(一)
猜你喜欢
随机推荐
Source insight project import and use tutorial
Return and job management of saltstack
Using Lex (Flex) to generate lexical analyzer of PL language
Know small and medium LAN WLAN
MySQL8 tmp_ table_ Size and Max_ heap_ table_ size
数字图像理论知识(一)(个人浅析)
1、 Relationship among CPU, memory and hard disk
English translation Arabic - batch English translation Arabic tools free of charge
云原生编程挑战赛火热开赛,51 万奖金等你来挑战!
[网络]跨区域网络的通信学习IPv4地址的分类和计算
How many types of rain do you know?
Labelme(一)
[C language] print pattern summary
Implementation of memcpy in C language
[C language] step jumping problem [recursion]
Article translation software - batch free translation software supports major translation interfaces
Token verification program index.php when configuring wechat official account server
Data system of saltstack
CodeIgnier框架实现restful API接口编程
Implementation of markdown editor in editor.md









