当前位置:网站首页>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 20002d18
analysis
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 .
边栏推荐
- Goland常用快捷键设置
- 【已解决】MySQL异常:ERROR 1045 (28000): Unknown error 1045,忘记初始密码
- TC397 QSPI(CPU)
- [datawhale team learning] task02: mathematical operation, string and text, list
- [most complete] install MySQL on a Linux server
- Can introduction
- 单测调用对象的私有方法
- 【最全】linux服务器上安装Mysql
- Network security - routing principle
- Resolution: div failed to get keyboard event
猜你喜欢
Linux服務器安裝Redis
Class template case - encapsulation of array classes
踩坑记录:supervisor 日志返回信息:redis扩展未安装
Linux服务器安装Redis
视频播放器(二):视频解码
Basic knowledge of system software development
All errors reported by NPM
nRF52832 GPIO LED
JS widget wave JS implementation of wave progress bar animation style
Starting MySQL ERROR! Couldn‘t find MySQL server (/usr/local/mysql/bin/mysqld_safe)
随机推荐
Write and run the first go language program
Embedded test process
QT generate random number qrandomgenerator
解决:div获取不到键盘事件
B站首个UP主付费观看视频还是来了!价格“劝退”网友
Running lantern effect JS text rotation effect realization
如果我在珠海,到哪里开户比较好?另外,手机开户安全么?
IDEA import导入的类明明存在,却飘红?
Develop common dependency Libraries
编写并运行第一个Go语言程序
[resolved] error 1290 (HY000): unknown error 1290
手机开户股票开户安全吗?开户需要准备什么?
Deploying web projects using idea
Network security - routing principle
【已实现】服务器jar包启动脚本、shell脚本
【已解决】ERROR 1290 (HY000): Unknown error 1290
Go common commands
已解决:initialize specified but the data directory has files in it. Aborting
Linux服务器安装Redis
The class imported by idea import clearly exists, but it is red?