当前位置:网站首页>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 .
边栏推荐
- 500 lines of code to understand the principle of mecached cache client driver
- 0211 embedded C language learning
- Blue Bridge Cup embedded_ STM32 learning_ Key_ Explain in detail
- Tensorflow customize the whole training process
- 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
- Dynamics 365 开发协作最佳实践思考
- A basic lintcode MySQL database problem
- SQL statement
- Computer graduation design PHP animation information website
- Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

SPI communication protocol

技术管理进阶——什么是管理者之体力、脑力、心力

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

leetcode3、實現 strStr()

2022 edition illustrated network pdf

Social networking website for college students based on computer graduation design PHP

Overview of spark RDD

Unity learning notes -- 2D one-way platform production method

2 power view

How does redis implement multiple zones?
随机推荐
论文笔记: 极限多标签学习 GalaXC (暂存, 还没学完)
0211 embedded C language learning
Grabbing and sorting out external articles -- status bar [4]
Computer graduation design PHP animation information website
Selenium element positioning (2)
Unity learning notes -- 2D one-way platform production method
Prepare for the autumn face-to-face test questions
Campus second-hand transaction based on wechat applet
1. Introduction to basic functions of power query
Genius storage uses documents, a browser caching tool
Leetcode3, implémenter strstr ()
Minecraft 1.16.5 biochemical 8 module version 2.0 storybook + more guns
How to improve the level of pinduoduo store? Dianyingtong came to tell you
Redis如何实现多可用区?
Bidding promotion process
PAT甲级 1033 To Fill or Not to Fill
leetcode3、實現 strStr()
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
Leetcode sum of two numbers
[depth first search notes] Abstract DFS