当前位置:网站首页>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 .
边栏推荐
- Selenium waiting mode
- SSM 程序集
- leetcode3、實現 strStr()
- Have a look at this generation
- How to set an alias inside a bash shell script so that is it visible from the outside?
- 729. My schedule I / offer II 106 Bipartite graph
- Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system
- Using SA token to solve websocket handshake authentication
- selenium 等待方式
- Flowable source code comments (36) process instance migration status job processor, BPMN history cleanup job processor, external worker task completion job processor
猜你喜欢
Using SA token to solve websocket handshake authentication
2022 edition illustrated network pdf
Blue Bridge Cup embedded_ STM32 learning_ Key_ Explain in detail
selenium 等待方式
NiO related knowledge (II)
Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system
Extracting key information from TrueType font files
0211 embedded C language learning
leetcode3、實現 strStr()
Redis string type
随机推荐
How to set an alias inside a bash shell script so that is it visible from the outside?
FTP server, ssh server (super brief)
A basic lintcode MySQL database problem
HDU_p1237_简单计算器_stack
模板_求排列逆序对_基于归并排序
2 power view
Install redis
安装php-zbarcode扩展时报错,不知道有没有哪位大神帮我解决一下呀 php 环境用的7.3
Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL learning notes - subquery exercise
阿里测开面试题
Gbase 8C database upgrade error
Virtual machine network, networking settings, interconnection with host computer, network configuration
模板_快速排序_双指针
Kubernetes stateless application expansion and contraction capacity
Genius storage uses documents, a browser caching tool
How does redis implement multiple zones?
Minecraft 1.18.1、1.18.2模组开发 22.狙击枪(Sniper Rifle)
D22:indeterminate equation (indefinite equation, translation + problem solution)
Leetcode sum of two numbers