当前位置:网站首页>The address value indicated by the pointer and the value of the object indicated by the pointer (learning notes)
The address value indicated by the pointer and the value of the object indicated by the pointer (learning notes)
2022-04-23 05:27:00 【What’smean】
The address value indicated by the pointer :
The pointer p As if The condition of the statement , The actual test is the value of the pointer itself , That is, the address value indicated by the pointer . If the pointer points to a real variable , Then its value must not be 0( Such as pointer in code p1), At this time, the condition is true ; If the pointer does not point to any object or is an invalid pointer ( Such as pointer in code p2), On the other hand p The use of will lead to unpredictable results .
The value of the object to which the pointer refers :
Dereference operator *p As if The condition of the statement , What is actually checked is the content of the object referred to by the pointer , In code is a pointer p1 The value referred to i I.e 0, If it's time to int The value is 0, Then the condition is false ; otherwise , If it's time to int Values are not for 0, The corresponding condition is true .
Code block :
#include<iostream>
using namespace std;
int main(){
int i = 0;
int *p1 = &i;
int *p2 = NULL;
if(p1){// Check pointer P1 The value of the indicated address
cout<<"p1 pass"<<endl;
}
if(p2){// Check pointer p2 The value of the indicated address
cout<<"p2 pass"<<endl;
}
if(*p1){// Quoting , Check pointer p1 The value of the content of the object
cout<<"*p1 pass"<<endl;
}
return 0;
}
Output results :
p1 pass // The pointer p1 The address has a real value, so the result is true
p2 no pass // The pointer p2 The address has no real value, so the result is false
*p1 no pass // Quoting *p1 The content value of the object is 0, So the result is false
Please press any key to continue . . .
版权声明
本文为[What’smean]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220544124456.html
边栏推荐
- 巴普洛夫与兴趣爱好
- Use pagoda + Xdebug + vscode to debug code remotely
- 2021-09-28
- 可执行程序执行流程
- 点击添加按钮--出现一个框框(类似于添加学习经历-本科-研究生)
- Graphics.FromImage报错“Graphics object cannot be created from an image that has an indexed pixel ...”
- C test calls the paddlesharp module to recognize pictures and words
- !!!!!!!!!!!!!!!!!!
- If I am PM's performance, movie VR ticket purchase display
- (十一)vscode代码格式化配置
猜你喜欢

How to add beautiful code blocks in word | a very complete method to sort out and compare

Quick app bottom navigation bar

Solution of how to log in with mobile phone verification code in wireless network

Good test data management, in the end how to do?

2021-09-27

分支与循环语句

Create process memory management copy_ Mm - processes and threads (IX)
Basic knowledge of redis

Intel SGX preliminary learning and understanding notes (continuously updated)

Uniapp wechat sharing
随机推荐
相机成像+单应性变换+相机标定+立体校正
分支与循环语句
What are the reasons for the failure of digital transformation?
双击.jar包无法运行解决方法
Log introduction and building web application
4 most common automated test challenges and Countermeasures
npm升级后问题,慌得一批
使用宝塔+xdebug+vscode远程调试代码
【openh264】cmake: msopenh264-static
(十一)vscode代码格式化配置
Domain driven model DDD (III) -- using saga to manage transactions
Click the Add button - a box appears (similar to adding learning experience - undergraduate - Graduate)
SQL Server检索SQL和用户信息的需求
App Store年交易额100万美元只缴15%佣金,中小开发者心里很矛盾
MySQL series - install MySQL 5.6.27 on Linux and solve common problems
Three of three JS (WEB GL) model deletion / scene emptying / simple sorting of memory release
After NPM was upgraded, there was a lot of panic
2021-10-12
Laravel routing settings
egg的static的前缀是可以修改惹,靴靴