当前位置:网站首页>Pointer learning
Pointer learning
2022-07-06 09:54:00 【@sen】
One 、 Defining pointer variables
(1) Type name :* Pointer variable name
char *pa; // Define a pointer variable that points to a character type
int *pb; // Define a pointer variable that points to an integer
(2) Take address operator and value operator
If you need to get the address of a variable , You can use the address operator (&):
char *pa=&a;
int *pb=&b;
If you need to access the data pointed to by the pointer variable , You can use the value operator (*):
printf(“%c,%d\n”,*pa,*pb);
#include<stdio.h>
int main()
{
char a = 'F';
int f = 123;
char *pa = &a;
int *pb = &f;
printf("a=%c\n", *pa); // Initial pointer variable
printf("f=%d\n", *pb);
*pa = 'C';
*pb += 1;
printf("now,a=%c\n", *pa); // Change the pointer variable
printf("now,f=%d\n", *pb);
printf("sizeof pa=%d\n", sizeof(pa)); // Print pointer length
printf("sizeof pb=%d\n", sizeof(pb));
printf("the adds a or b is:%p\n",pa); // Access pointer address
printf("the adds a or b is:%p\n", pb);
return 0;
}
** You need to avoid uninitialized pointers
#include <stdio.h>
int main()
{
int *a; // Uninitialized pointer
*a = 123;
return 0;
}边栏推荐
- 学习单片机对社会的帮助是很大的
- 硬件工程师的真实前途我说出来可能你们不信
- Compress decompress
- MapReduce instance (IV): natural sorting
- Scoped in webrtc_ refptr
- C杂讲 文件 续讲
- Listen to my advice and learn according to this embedded curriculum content and curriculum system
- O & M, let go of monitoring - let go of yourself
- CAPL 脚本对.ini 配置文件的高阶操作
- [Yu Yue education] Wuhan University of science and technology securities investment reference
猜你喜欢
随机推荐
Listen to my advice and learn according to this embedded curriculum content and curriculum system
May brush question 26 - concurrent search
CANoe CAPL文件操作目录合集
五月刷题27——图
MapReduce working mechanism
单片机如何从上电复位执行到main函数?
在CANoe中通过Panel面板控制Test Module 运行(高级)
五月集训总结——来自阿光
【深度學習】語義分割-源代碼匯總
Basic concepts of libuv
硬件工程师的真实前途我说出来可能你们不信
C杂讲 双向循环链表
CAPL脚本中关于相对路径/绝对路径操作的几个傻傻分不清的内置函数
Une grande vague d'attaques à la source ouverte
[deep learning] semantic segmentation - source code summary
单片机实现模块化编程:思维+实例+系统教程(实用程度令人发指)
51单片机进修的一些感悟
How does the single chip microcomputer execute the main function from power on reset?
Control the operation of the test module through the panel in canoe (primary)
竞赛vscode配置指南







