当前位置:网站首页>C language learning log 1.16
C language learning log 1.16
2022-06-13 04:57:00 【Today is also a day without baldness】
Pointer arithmetic :
+n: Add... To a pointer 1 Indicates that you want the pointer to point down n A variable . for example : int a[10]; int *p = a; *(p+1) ---->a[1]
If the pointer is not pointing to the space allocated continuously on one side , Such as arrays , Then this operation is meaningless .
Other operators (+、-、+=、-=) from + You know :“-” Is the pointer pointing forward to the variable .
*p++: Take out p The data referred to comes from , When you're done, drop in p Move to the next position ,* High priority though , But no ++ high , It is often used for continuous space operation of array class , In some CPU On , This can be translated directly into an assembly instruction .
Pointer comparison :
<,<=,==,>,>=,!= Can do... On the pointer , Compare their addresses in memory , The cell addresses in the array must be linearly increasing .
0 Address :
In every program 0 Address , however 0 Address is usually an address that can't be touched , So your pointer should not have 0 value , So you can use 0 Address to show special things :
The returned pointer is invalid
The pointer is not really initialized ( Initialize to 0)
NULL Is a predefined symbol , stay C Language is used to express 0 Address , Because some compilers don't want you to use 0 To express 0 Address .
The type of pointer :
No matter what kind of , All pointers are the same size , Because it's all addresses . But pointers to different types cannot be assigned directly to each other , This is to avoid using the wrong pointer .
Type conversion :void* A pointer indicating that you don't know what to point to , Calculate with char* identical ( But it's not connected ), Pointers can also be converted to types , for example : int *p=&i void*q=(void*)p; It doesn't change p Type of variable referred to , But let the back pass with different eyes p Look at the variables it refers to , from q Just look at it i As int But as void;
What is the pointer used for :
1. Use as a parameter when large data needs to be passed in .2. After passing in the array, operate on the array .3. Function returns more than one result , You need to use functions to modify more than one variable .4. Dynamically requested memory .
边栏推荐
- Infinite cycle scrolling code Alibaba international station store decoration code base map scrolling black translucent display effect custom content decoration code full screen display
- Clause 32: moving objects into closures using initialization capture objects
- CMB written test graphical reasoning
- Analysis of the principle of V-model and its application in user defined components
- SQL notes
- All blog navigation
- Shell built-in string substitution
- QT interface rendering style
- PostgreSQL Guide: inside exploration (Chapter 10 basic backup and point in time recovery) - Notes
- josephus problem
猜你喜欢
Must know must know -c language keywords
无限循环滚动代码阿里巴巴国际站店铺装修代码底图滚动黑色半透明显示效果自定义内容装修代码全屏显示
2021TPAMI/图像处理:Exploiting Deep Generative Prior for Versatile Image Restoration and Manipulation
Shell built-in string substitution
Kaggle time series tutorial
Brick story
RMQ、LCA
Cesium:CesiumLab制作影像切片与切片加载
Section 3 - functions
RuoYi-Cloud启动教程(手把手图文)
随机推荐
C language exercise 1
Analysis on the similarities and differences of MVC, MVP and mvvc
135. distribute candy
How to handle async/await error messages gracefully
Force buckle 25 A group of K flipped linked lists
约瑟夫问题
[JS solution] leedcode 117 Populate the next right node pointer II for each node
Force deduction 121 questions
PostgreSQL Guide: inside exploration (Chapter 10 basic backup and point in time recovery) - Notes
QT brushes and brushes
Ruoyi cloud startup tutorial (hand-held graphics)
Clause 31: avoid default capture mode
Collection of some compatibility issues
Construction problem of D Xiaohong
[JS solution] leedcode 200 Number of islands
PowerShell plus domain add computer module
Win8.1和Win10各自的優勢
无限循环滚动代码阿里巴巴国际站店铺装修代码底图滚动黑色半透明显示效果自定义内容装修代码全屏显示
Third party comment plugin
Kaggle time series tutorial