当前位置:网站首页>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
边栏推荐
- A chip company fell in round B
- leetcode day3 超过经理收入的员工
- How many types of rain do you know?
- KPMG China: insights into information technology audit projects of securities fund management institutions
- Thoroughly understand bit operations -- and (&), not (~), or (|), XOR (^)
- Cdga | how can the industrial Internet industry do a good job in data governance?
- 【NPP安装插件】
- Basic concept and essence of Architecture
- 认识中小型局域网WLAN
- Concurrent programming, do you really understand?
猜你喜欢

Common APIs in string

Advanced notes (Part 2)

Design of air combat game based on qtgui image interface

云计算笔记part.2——应用管理

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

Thoroughly understand bit operations - shift left, shift right

English translation Portuguese - batch English conversion Portuguese - free translation and conversion of various languages

Basic concept and essence of Architecture

Cloud computing notes part.1 - system management

Know small and medium LAN WLAN
随机推荐
Thoroughly understand bit operations -- and (&), not (~), or (|), XOR (^)
[C language] simulation implementation of pow function (recursion)
Implementation of strcat in C language
How to write the SQL statement of time to date?
[C language] Pointer elementary knowledge points
Implementation of memcpy in C language
Intermediate soft test (system integration project management engineer) high frequency test site
JS batch add event listening onclick this event delegate target currenttarget onmouseenter OnMouseOver
[C language] Pointer advanced knowledge points
Longest Palindromic Substring
High beam software has obtained Alibaba cloud product ecological integration certification, and is working with Alibaba cloud to build new cooperation
The results of the second quarter online moving people selection of "China Internet · moving 2022" were announced
Andorid system layout, values, drawable adaptation
Why is there no log output in the telnet login interface?
11. Learn MySQL union operator
Theoretical knowledge of digital image (I) (personal analysis)
Prometheus deployment
What is the process of swing event processing?
Leetcode day2 连续出现的数字
Can China make a breakthrough in the future development of the meta universe and occupy the highland?