当前位置:网站首页>Initial understanding of pointer variables
Initial understanding of pointer variables
2022-07-06 02:16:00 【Awei II】
1、 Define a pointer variable
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
int a = 10;//a Space to be allocated in memory --4 byte
printf("%p\n", &a);//%p Designed for printing addresses
int* pa = &a;//pa It is used for storing addresses , stay C In language pa It's called pointer variable
//* explain pa It's a pointer variable
//int explain pa Modification is int Object of type
char b = 'w';
char* pa1 = &b;
}
a Space to be allocated in memory --4 byte
%p Designed for printing addresses
int* pa = &a;//pa It is used for storing addresses , stay C In language pa It's called pointer variable
* explain pa It's a pointer variable
int explain pa Modification is int Object of type
2、 Pointer size
How to determine the size of a pointer ?
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
printf("%d\n", sizeof(char*));
printf("%d\n", sizeof(int*));
printf("%d\n", sizeof(float*));
printf("%d\n", sizeof(double*));
printf("%d\n", sizeof(short*));
printf("%d\n", sizeof(long*));
printf("%d\n", sizeof(long long*));
// All sizes are 8 byte
}
The output is as follows
so , Pointer sizes are 8 byte , The pointer size is the same , This is because pointers are used to store addresses , How much space the pointer needs depends on how much space the address storage needs ; such as 32 Bit machine pointer size is 4 byte ,64 Bit machine pointer size is 8 byte .
3、 Use the dereference operator * To change the value of a local variable
There is the following code snippet
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
int a = 25;
int* pa = &a;
*pa = 56;//* Is the dereference operator ,*pa It is through pa find a Address changed after a Value
printf("%d\n", a);
}
Output is as follows
so , among a The value of , This is because * Dereference operator ,*pa It is through pa find a Address changed after a Value .
边栏推荐
- Online reservation system of sports venues based on PHP
- Get the relevant information of ID card through PHP, get the zodiac, get the constellation, get the age, and get the gender
- [depth first search notes] Abstract DFS
- Sword finger offer 12 Path in matrix
- Computer graduation design PHP college student human resources job recruitment network
- Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail
- 更改对象属性的方法
- Card 4G industrial router charging pile intelligent cabinet private network video monitoring 4G to Ethernet to WiFi wired network speed test software and hardware customization
- Kubernetes stateless application expansion and contraction capacity
- The intelligent material transmission system of the 6th National Games of the Blue Bridge Cup
猜你喜欢
Derivation of Biot Savart law in College Physics
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
How to improve the level of pinduoduo store? Dianyingtong came to tell you
【社区人物志】专访马龙伟:轮子不好用,那就自己造!
零基础自学STM32-复习篇2——使用结构体封装GPIO寄存器
PHP campus movie website system for computer graduation design
PAT甲级 1033 To Fill or Not to Fill
[depth first search notes] Abstract DFS
爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
[robot library] awesome robots Libraries
随机推荐
2022 edition illustrated network pdf
PAT甲级 1033 To Fill or Not to Fill
Open source | Ctrip ticket BDD UI testing framework flybirds
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Minecraft 1.16.5 biochemical 8 module version 2.0 storybook + more guns
Pangolin Library: subgraph
RDD partition rules of spark
论文笔记: 极限多标签学习 GalaXC (暂存, 还没学完)
Global and Chinese markets of screw rotor pumps 2022-2028: Research Report on technology, participants, trends, market size and share
500 lines of code to understand the principle of mecached cache client driver
729. 我的日程安排表 I / 剑指 Offer II 106. 二分图
2022年版图解网络PDF
Minecraft 1.16.5 生化8 模组 2.0版本 故事书+更多枪械
Text editing VIM operation, file upload
机器学习训练与参数优化的一般过程 (讨论)
leetcode3、實現 strStr()
Redis如何实现多可用区?
Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system
Redis string type
正则表达式:示例(1)