当前位置:网站首页>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 .
边栏推荐
- 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
- [solution] add multiple directories in different parts of the same word document
- 01. Go language introduction
- 模板_求排列逆序对_基于归并排序
- Selenium element positioning (2)
- leetcode-两数之和
- Computer graduation design PHP campus restaurant online ordering system
- 2022年版图解网络PDF
- 论文笔记: 极限多标签学习 GalaXC (暂存, 还没学完)
- Bidding promotion process
猜你喜欢

Minecraft 1.18.1, 1.18.2 module development 22 Sniper rifle

leetcode3、实现 strStr()
![[robot library] awesome robots Libraries](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[robot library] awesome robots Libraries

The intelligent material transmission system of the 6th National Games of the Blue Bridge Cup

Concept of storage engine

Kubernetes stateless application expansion and contraction capacity

在线怎么生成富文本

Audio and video engineer YUV and RGB detailed explanation

Virtual machine network, networking settings, interconnection with host computer, network configuration

使用npm发布自己开发的工具包笔记
随机推荐
Genius storage uses documents, a browser caching tool
Comments on flowable source code (XXXV) timer activation process definition processor, process instance migration job processor
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
PHP campus movie website system for computer graduation design
vs code保存时 出现两次格式化
500 lines of code to understand the principle of mecached cache client driver
SQL statement
1. Introduction to basic functions of power query
通过PHP 获取身份证相关信息 获取生肖,获取星座,获取年龄,获取性别
Selenium waiting mode
Audio and video engineer YUV and RGB detailed explanation
Kubernetes stateless application expansion and contraction capacity
【社区人物志】专访马龙伟:轮子不好用,那就自己造!
Pangolin Library: subgraph
Using SA token to solve websocket handshake authentication
Publish your own toolkit notes using NPM
Ali test open-ended questions
genius-storage使用文档,一个浏览器缓存工具
01. Go language introduction
在线怎么生成富文本