当前位置:网站首页>Basic grammar of C language -- pointer (character, one-dimensional array) learning
Basic grammar of C language -- pointer (character, one-dimensional array) learning
2022-06-26 09:50:00 【Tanzanian auduvi Canyon expert】
Pointer understanding :
- Pointer is also a variable ; Only the address , No constants ;
- The pointer generally uses p、q、m、n To express , no need b Express ;
- The type of pointer is consistent with the type of variable it points to ;
- Pointer operator : * 、 & ( * For the pointer ;& Representative address )
int Occupy memory 2 individual b
float Occupy memory 4 individual b
Ordinary variable pointer
int a=3,b=4,d;
int *b=&a; // * For the pointer ;& Representative address
int *b=5; // Will report a mistake , Because only the address , No constants
printf("%d",a);
printf("%d",*b); // Want to use a It's worth it , use *b ; b yes a The pointer to ;b yes a The address of ;*b Represents the value of the variable pointed to by the pointer
printf("%d",b); // Want to use a If you have an address , use b , The memory address is a hexadecimal value ; Computer memory is generally in the form of 16 Base to represent .b Indicates the address of the variable pointed to by the pointer
int c=*b+1; // ;
printf("%d",c);
p1=&a; // It can't be *p1=&a , Will report a mistake
p2=&b;
d=*p1+*p2;
p2=&a;
p=&(a+1); // Wrong writing
Print out :
3
3
22316
4
// There are two ways to define pointers
int a, *p; // One
p=&a;
int a, *p=&a; // Two
Maximum number of pointer versions :
int main(int argc, char *argv[]) {
int a,*p=&a,i,max=0,*p1=&max;
for(i;i<10;i++){
scanf("%d",p);
if(*p>*p1){
p1=p;
}
}
printf(" The maximum number is :%d",*p1);
return 0;
}
Array variable pointer ;
p To whose address , At this time, replace who to operate ;
Be careful :
The array name itself is a special pointer , It's a constant , Cannot participate in operation , such as :
int a[]={1,2} 、char a[]=“Hello W”
a --> Array name itself , The default is the first element of the array
The pointer p It's a variable , such as :
*p=“Hello W”
int *p,i;
int a={
1,2,3,4,5};
p=a;// *p=a[0]=1
p++; // 2
p=a+4;
printf("%d", *p); // 5 It mainly depends on where the pointer points , Wherever you move, it means where you are
p--; // 4
main() {
// Napoch 12 Sum of items Pointer version
int *p,sum=2;
int a[12]; // It's usually 12 Elements ;10、11 It's fine too , however 9 No way. , Because there is a sentence below *p=*(p-1)+*(p-2), The pointer can move , Two elements can be extended here
p=a;
*p=1;
printf(" The first is %d",*p);
p++;
*p=1;
printf(" The second is %d",*p);
p++; // Need to navigate to the subscript 2 Start , That is the first. 3 A start ; perhaps for In parentheses p=a+2
for(;p<=(a+11);p++){
// p<(a+11) Or you could write it as p<=a+11
*p=*(p-1)+*(p-2);
printf("\n%d",*p); // a[i]
sum=sum+*p;
}
printf("\n Before Fibonacci series 12 Xiang He =%d",sum);
return 0;
}
The relationship between pointer and array :
Two dimensional arrays are generally reserved i How to deal with ;
One dimensional arrays can be used either way .
边栏推荐
- 教你用shell脚本检测服务器程序是否在运行
- 【CVPR 2019】Semantic Image Synthesis with Spatially-Adaptive Normalization(SPADE)
- Jz2440--- using uboot burning program
- c语言语法基础之——函数 小程序 求阶乘
- 2021年全国职业院校技能大赛(中职组)网络安全竞赛试题(1)详细解析教程
- 【轨迹规划】Ruckig库的测试
- Comprehensive interpretation! Use of generics in golang
- The 100000 line transaction lock has opened your eyes.
- Leetcode basic calculator 224 227. follow up 394
- install ompl.sh
猜你喜欢
Mysql database field query case sensitive setting
深度学习(初识tensorflow2.版本)之三好学生成绩问题(1)
online trajectory generation
The first techo day Tencent technology open day, 628
十万行事务锁,开了眼界了。
Several connection query methods of SQL (internal connection, external connection, full connection and joint query)
Curriculum learning (CL)
online trajectory generation
Badge collection 6:api\_ Use of level
logback
随机推荐
PHP does not allow images to be uploaded together with data (no longer uploading images before uploading data)
pcl install
VI summary of common commands
SQL高级教程
What you need to know to test -- URL, weak network, interface, automation
Leetcode connected to rainwater series 42 (one dimension) 407 (2D)
Badge series 8: generate a personalized Badge
Redis notes (16) - info instructions and command line tools (view memory, status, number of client connections, monitoring server, scan large keys, sampling server, execute batch commands, etc.)
c语言语法基础之——函数定义学习
同花顺炒股软件安全性怎样?在同花顺怎么开户
逻辑英语结构【重点】
LeetCode 498. Diagonal traversal
c语言语法基础之——函数嵌套、递归 小程序斐波那契之和、阶乘
节流,防抖,new函数,柯里化
Champions League data set (Messi doesn't cry - leaving Barcelona may reach another peak)
LeetCode 基本计算器 224. 227. follow up 394
Opencv depthframe - > pointcloud causes segmentation fault!
Logical English structure [key points]
Throttling, anti chattering, new function, coriolism
c语言语法基础之——指针( 多维数组、函数、总结 ) 学习