当前位置:网站首页>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 .
边栏推荐
- Formatting occurs twice when vs code is saved
- [eight part essay] what is the difference between unrepeatable reading and unreal reading?
- Global and Chinese markets of nasal oxygen tubes 2022-2028: Research Report on technology, participants, trends, market size and share
- leetcode3、實現 strStr()
- MySQL index
- Publish your own toolkit notes using NPM
- A basic lintcode MySQL database problem
- 剑指 Offer 30. 包含min函数的栈
- Adapter-a technology of adaptive pre training continuous learning
- Concept of storage engine
猜你喜欢

Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system

Computer graduation design PHP animation information website

技术管理进阶——什么是管理者之体力、脑力、心力
![[solution] add multiple directories in different parts of the same word document](/img/22/32e43493ed3b0b42e35ceb9ab5b597.jpg)
[solution] add multiple directories in different parts of the same word document

PAT甲级 1033 To Fill or Not to Fill

【社区人物志】专访马龙伟:轮子不好用,那就自己造!

2022 PMP project management examination agile knowledge points (8)

Use the list component to realize the drop-down list and address list

PHP campus movie website system for computer graduation design

Adapter-a technology of adaptive pre training continuous learning
随机推荐
模板_快速排序_双指针
PHP campus financial management system for computer graduation design
Redis如何实现多可用区?
NiO related knowledge (II)
通过PHP 获取身份证相关信息 获取生肖,获取星座,获取年龄,获取性别
Compact lidar global and Chinese markets 2022-2028: technology, participants, trends, market size and share Research Report
安装php-zbarcode扩展时报错,不知道有没有哪位大神帮我解决一下呀 php 环境用的7.3
2022年版图解网络PDF
零基础自学STM32-复习篇2——使用结构体封装GPIO寄存器
[depth first search notes] Abstract DFS
Blue Bridge Cup embedded_ STM32 learning_ Key_ Explain in detail
Leetcode sum of two numbers
genius-storage使用文档,一个浏览器缓存工具
Comments on flowable source code (XXXV) timer activation process definition processor, process instance migration job processor
[robot hand eye calibration] eye in hand
How to generate rich text online
同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
MySQL learning notes - subquery exercise
Use Scrollview and tabhost to realize vertical scrollbars and tabs
Paper notes: graph neural network gat