当前位置:网站首页>Variable storage unit and pointer
Variable storage unit and pointer
2022-06-30 07:18:00 【liwuxing】
Test procedure
#include <rtthread.h>
int main(void)
{
char num = '1'; // Defining character variables num, And assign characters ‘1’
char *ptr = # // Defines a pointer to a character variable ptr, And point to num Variable
char **p_ptr = &ptr; // Defines a pointer to a character variable p_ptr, And point to ptr Variable
rt_kprintf(" The pointer ptr The value of the point %x\n",*ptr);
rt_kprintf(" The pointer ptr Value %p\n",ptr);
rt_kprintf(" Variable num The value of is output in hexadecimal format %x\n",num);
rt_kprintf(" Variable num The value of is output in character format %c\n",num);
rt_kprintf(" Variable num The address of %p\n",&num);
rt_kprintf(" Point to ptr Pointer value of pointer variable %p\n",p_ptr);
return 0;
}After executing the program, the output is as follows :
The pointer ptr The value of the point 31
The pointer ptr Value 20002d1c
Variable num The value of is output in hexadecimal format 31
Variable num The value of is output in character format 1
Variable num The address of 20002d1c
Point to ptr Pointer value of pointer variable 20002d18analysis
There are three variables involved in the program , Namely num、ptr、p_ptr, Their values are hexadecimal 31、20002d1c、20002d18. They are all variables , Although the declared types are char Character , But for the 32 Bit address system , The hands are all 32bit, That accounts for 4 byte ; And character variables num Occupy 1 byte .ptr、p_ptr Is a special variable , Is the variable used to hold the pointer , It is conventionally called pointer variable , In fact, what is saved is that of the computer system “ Address ”.
Three variables num、ptr、p_ptr The location in the memory is shown in the figure below :

When the computer compiles, it divides the memory 3 Space binding this 3 A variable , When writing a program , The values stored in the corresponding storage space are manipulated by variables . This system uses a small terminal to store data , That is, the low order address stores the data of low order bytes .

Variables have three elements
1. data type (Type): Decide how much space to allocate in memory
2. Variable name (Name) : The name of the manipulation of the allocated space when the program is written
3. value (Value) : Data stored in space
When debugging a program , You can usually view these elements :

Common variables num Represents the value of the storage space ,“&num” For its address . For pointer variables ptr Come on ,ptr Save address ,“*ptr” Represents the value whose address points to the space ,“&ptr” Represents the address where the pointer space is saved . and “*num” Indicates that num The value is the content of the address , because num Only 1 byte , The compiler will consider an error and cannot generate an executable , so “*num” It makes no sense .

边栏推荐
- [datawhale team learning] task02: mathematical operation, string and text, list
- 2022年6月29日--使用C#迈出第一步--使用 C# 中的“if”、“else”和“else if”语句向代码添加决策逻辑
- 【SemiDrive源码分析】【X9芯片启动流程】34 - RTOS侧 Display模块 sdm_display_init 显示初始化源码分析
- Running lantern effect JS text rotation effect realization
- 【已实现】服务器jar包启动脚本、shell脚本
- Connection flood attack principle
- JS widget wave JS implementation of wave progress bar animation style
- [most complete] install MySQL on a Linux server
- Cubemx completes STM32F103 dual serial port 485 transceiver transmission
- The class imported by idea import clearly exists, but it is red?
猜你喜欢

MAX6675 usage notes

【最全】linux服务器上安装Mysql

Linux服务器安装Redis

Can introduction

Starting MySQL ERROR! Couldn‘t find MySQL server (/usr/local/mysql/bin/mysqld_safe)

Minecraft 1.16.5模组开发(五十) 书籍词典 (Guide Book)

Cubemx completes STM32F103 dual serial port 485 transceiver transmission

Traverse map

Linux server installation redis

2021-07-02
随机推荐
Merge: extension click the El table table data to expand
Utilisation de la commande grep
JS create PDF file
[solved] failed! Error: Unknown error 1130
Daemon and user threads
js创建pdf文件
Detailed analysis of message signals occupying multiple bytes and bits
【已解决】MySQL异常:ERROR 1045 (28000): Unknown error 1045,忘记初始密码
Can introduction
Connection Flood攻击原理
模拟接口没声明异常抛出异常
Linux服务器安装Redis
Linu基础-分区规划与使用
next InitializeSecurityContext failed: Unknown error (0x80092012) - 吊销功能无法检查证书是否吊销。
app quits unexpectedly
大学刚毕业不知道做什么工作怎么办?
Class template case - encapsulation of array classes
年轻人搞副业有多疯狂:月薪3000,副业收入3W
【Hot100】11. Container with the most water
Keil serial port redirection