当前位置:网站首页>The basis of C language grammar -- pointer (multidimensional array, function, summary) learning
The basis of C language grammar -- pointer (multidimensional array, function, summary) learning
2022-06-26 09:50:00 【Tanzanian auduvi Canyon expert】
Normal pointer :
Two dimensional array , Generally, there are several rows and columns ;
If more than one ordinary pointer is defined , This pointer only represents the address of the row , Instead of an element address , such as :
int a[3][3]={
1,2,3,4,5,6,7,8,9};
int *p;
p=a; //
printf("%d\n",*p); // 1 The element values of the first row and the first column
p=a+1;
printf("%d\n",*p); // 4 The element values in the first column of the second row
You can define a pointer to a specified address :
int a[3][3]={
1,2,3,4,5,6,7,8,9};
int *p;
p=&a[1][1]; // The address of the element in the second row and the second column
printf("%d\n",*p); // 5 The element values of the first row and the first column
p++;
printf("%d\n",*p); // 6 The element values in the second row and the third column
p=a+1; // The second line
printf("%d\n",*p); // 4 The element values in the first column of the second row
int main(int argc, char *argv[]) {
/* 1 2 1 3 2 1 4 3 2 1 5 4 3 2 1 */
int a[5][5];
int i,j;
for(i=0;i<5;i++){
for(j=0;j<5;j++){
// a[i][j]=i-j+1; // Non pointer version
*(a[i]+j)=i-j+1; // Pointer version
*(*(a+i)+j)=i-j+1; // Pointer version
if(i>=j){
// printf(" %d", a[i][j]); // Non pointer version
// printf(" %d", *(a[i]+j)); // Pointer version
printf(" %d", *(*(a+i)+j)); // Pointer version
}
}
printf("\n");
}
return 0;
}
Array pointer :
Define line pointer ( Array pointer ): You can use *(*(p+i)+j, Otherwise, the report will be wrong , Only use *(*(a+i)+j
int a[3][3]={
1,2,3,4,5,6,7,8,9};
int (*p)[3]; // Array row pointer
Several pointer operations on arrays :
Notice the commas in the figure , The execution order is from right to left , If it is a comma, change it to a multiplication sign , It's from left to right
int a[]={
1,2,3},y,*p=&a[2];
y=*--p;
y Value : 2
Logic :p The initial pointing subscript is 2 The address of , First --, Move to subscript 1, then * Value , The table below for 1 The address of , The value is 2
int a[]={
1,2,3,4,5,6},*p=a;
*p++ * *++p The value of is :3
Logic : Multiplication sign , From left to right , First *p=1, Then add the pointer 1, In execution ++p, The pointer is adding 1, And then take *++p=3 , Last 1*3=3
A function pointer :
int max(int a, int b){
}
int (*p)()
max(a,b) --> (*p)(a,b)
Pointer array :
Definition :
Each subscript variable is a pointer variable , It's an address , It is mainly used to handle variable length multiple strings .
understand : Pointer array is not the same concept as the previous array pointer , Pointer arrays are special in that all elements are an address
style :
int *b[3]={ a,&a[1] }
Pointer summary :
// Area of circle
double area(int r){
return 3.14*r*r;
}
int main(int argc, char *argv[]) {
double (*p)(); // Note that the type must be consistent with the function type , If the function is double, Here is int, The result will be 4199728.00000
p=area;
int i=2;
double result;
result=(*p)(i);
printf("%f",result); // 12.560000
return 0;
}
边栏推荐
- The third-party extension package of thinkphp6.0 supports uploading to Alibaba cloud and qiniu cloud
- Speed test of adding, deleting, modifying and querying 5million pieces of data in a single MySQL table
- LeetCode 0710. Random numbers in the blacklist - preprocessing implementation o (1) value
- PHP extracts TXT text to store the domain name in JSON data
- Leetcode refers to offer II 091 Paint house - modify in place
- What you need to know to test -- URL, weak network, interface, automation
- Force buckle ----- remove the maximum and minimum values from the array
- SQL modification of table structure
- My creation anniversary
- logback
猜你喜欢
MapReduce & yarn theory
力扣------从数组中移除最大值和最小值
工企专利匹配数据(数十万数据量)1998-2014年
VI summary of common commands
install realsense2: The following packages have unmet dependencies: libgtk-3-dev
做测试需要知道的内容——url、弱网、接口、自动化、
Wechat official account reported error 10003
[Journal of Computer Aided Design & computer graphics] overview of research on pedestrian re recognition methods based on generated countermeasure network
How does flutter transfer parameters to the next page when switching pages?
Explained: A Style-Based Generator Architecture for GANs (StyleGAN)
随机推荐
Badge series 4: use of circle Ci
SQL modification of table structure
QPM performance monitoring components - General
Redis notes (15) - Pipeline (the client packages and sends batch commands to save network overhead)
Regular expression learning
教你用shell脚本检测服务器程序是否在运行
Thinkphp5 using the composer installation plug-in prompts that the PHP version is too high
jz2440---使用uboot烧录程序
My creation anniversary
【轨迹规划】Ruckig库的测试
测试实践——app 测试注意点
Leetcode connected to rainwater series 42 (one dimension) 407 (2D)
爬虫相关文章收藏:pyppeteer 、Burpsuite
我的创作纪念日
安装 新版本cmake & swig & tinyspline
LeetCode 接雨水系列 42.(一维) 407.(二维)
Force buckle ----- remove the maximum and minimum values from the array
Logview Pro can be used if the log is too large
Introduction to QPM
c语言语法基础之——函数嵌套、递归 小程序斐波那契之和、阶乘