当前位置:网站首页>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;
}
边栏推荐
- Hugo blog graphical writing tool -- QT practice
- [untitled]
- Vh6501 Learning Series
- Nc29 search in two-dimensional array
- Cooperative development in embedded -- function pointer
- 五月集训总结——来自阿光
- Hero League rotation chart manual rotation
- Hero League rotation map automatic rotation
- [Yu Yue education] reference materials of power electronics technology of Jiangxi University of science and technology
- Counter attack of noodles: redis asked 52 questions in a series, with detailed pictures and pictures. Now the interview is stable
猜你喜欢
Oom happened. Do you know the reason and how to solve it?
Selection of software load balancing and hardware load balancing
DCDC power ripple test
MapReduce instance (x): chainmapreduce
Elk project monitoring platform deployment + deployment of detailed use (II)
Programmation défensive en langage C dans le développement intégré
How can I take a shortcut to learn C language in college
Combined search /dfs solution - leetcode daily question - number of 1020 enclaves
Learning SCM is of great help to society
C杂讲 双向循环链表
随机推荐
018.有效的回文
嵌入式开发比单片机要难很多?谈谈单片机和嵌入式开发设计经历
Elk project monitoring platform deployment + deployment of detailed use (II)
六月刷题02——字符串
Une grande vague d'attaques à la source ouverte
五月集训总结——来自阿光
May brush question 26 - concurrent search
竞赛vscode配置指南
五月刷题03——排序
硬件工程师的真实前途我说出来可能你们不信
Bugku web guide
MapReduce instance (IV): natural sorting
在CANoe中通過Panel面板控制Test Module 運行(初級)
Safety notes
Teach you how to write the first MCU program hand in hand
【深度學習】語義分割-源代碼匯總
Redis distributed lock implementation redison 15 questions
Why is 51+ assembly in college SCM class? Why not come directly to STM32
机械工程师和电气工程师方向哪个前景比较好?
018. Valid palindromes