当前位置:网站首页>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;
}
边栏推荐
- Industrial and enterprise patent matching data (hundreds of thousands of data) 1998-2014
- 自动化测试——pytest本身及第三方模块介绍及使用
- pcl install
- 逻辑英语结构【重点】
- Daily-used English phrases
- Summary of common commands of vim
- Notes on sports planning on November 22, 2021
- 教你用shell脚本检测服务器程序是否在运行
- A Style-Based Generator Architecture for Generative Adversarial Networks
- Badge collection 6:api\_ Use of level
猜你喜欢

2021-11-29 quintic polynomial of trajectory planning

逻辑英语结构【重点】

MapReduce & yarn theory

PHP extracts TXT text to store the domain name in JSON data

【CVPR 2019】Semantic Image Synthesis with Spatially-Adaptive Normalization(SPADE)

Install new version cmake & swig & tinyspline

online trajectory generation

install opencv-contrib-dev to use aruco code

做测试需要知道的内容——url、弱网、接口、自动化、

logback
随机推荐
SQL advanced tutorial
This new change of go 1.16 needs to be adapted: the changes of go get and go install
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.npm ER
【CVPR 2019】Semantic Image Synthesis with Spatially-Adaptive Normalization(SPADE)
Test instructions - common interface protocol analysis
Leetcode connected to rainwater series 42 (one dimension) 407 (2D)
Leetcode refers to offer II 091 Paint house - modify in place
LeetCode 0710. Random numbers in the blacklist - preprocessing implementation o (1) value
LeetCode 498. Diagonal traversal
I am in Zhongshan. Where can I open an account? Is online account opening safe?
自动化测试——关于unitest与pytest初始化共存问题
Daily-used English phrases
LeetCode 958. Completeness checking of binary tree
SQL 函数
VI summary of common commands
The third-party extension package of thinkphp6.0 supports uploading to Alibaba cloud and qiniu cloud
How about the security of flush stock trading software? How to open an account in flush
pcl install
LeetCode 基本计算器 224. 227. follow up 394
LeetCode 0710.黑名单中的随机数 - 预处理实现O(1)取值