当前位置:网站首页>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 .
边栏推荐
- PHP campus movie website system for computer graduation design
- Bidding promotion process
- 【clickhouse】ClickHouse Practice in EOI
- Use the list component to realize the drop-down list and address list
- Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system
- 2 power view
- 正则表达式:示例(1)
- leetcode3、实现 strStr()
- leetcode-两数之和
- VIM usage guide
猜你喜欢
[depth first search notes] Abstract DFS
Computer graduation design PHP college classroom application management system
Pangolin Library: subgraph
Leetcode sum of two numbers
Jisuanke - t2063_ Missile interception
Tensorflow customize the whole training process
爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
Audio and video engineer YUV and RGB detailed explanation
PHP campus financial management system for computer graduation design
Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system
随机推荐
MySQL lethal serial question 1 -- are you familiar with MySQL transactions?
Computer graduation design PHP enterprise staff training management system
Numpy array index slice
Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
2 power view
【社区人物志】专访马龙伟:轮子不好用,那就自己造!
Get the relevant information of ID card through PHP, get the zodiac, get the constellation, get the age, and get the gender
Pangolin Library: subgraph
Global and Chinese markets of general purpose centrifuges 2022-2028: Research Report on technology, participants, trends, market size and share
Blue Bridge Cup embedded_ STM32 learning_ Key_ Explain in detail
Redis key operation
[robot hand eye calibration] eye in hand
好用的 JS 脚本
阿里测开面试题
[Clickhouse] Clickhouse based massive data interactive OLAP analysis scenario practice
Publish your own toolkit notes using NPM
selenium 元素定位(2)
爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
Gbase 8C database upgrade error
Global and Chinese market of wheelchair climbing machines 2022-2028: Research Report on technology, participants, trends, market size and share