graph LR
classDef className fill:white,stroke:#333,stroke-width:1px;
id3[*p 形参]-->id1[7]
subgraph arr数组
id[10]-->id1[7]
id1[7]-->id2[5]
end
subgraph *p
id3[*p 形参]
end
class id,id1,id2,id3 className;
最后:
graph LR
classDef className fill:white,stroke:#333,stroke-width:1px;
id4[*p]-->id1[3]
id3[*p 形参]-->id[10]
subgraph *p 形参
id3[*p 形参]
end
subgraph *p
id4[*p]
end
subgraph arr数组
id[10]-->id1[3]
id1[3]-->id2[5]
end
class id,id1,id2,id3,id4 className;
注意:*p--=3实际上是*p=3,然后(p--)
1 2 3 4 5 6 7 8 9 10 11 12
#include<iostream> using namespace std; int func(int *p){ return (*p--=3)-1; } int main() { int arr[]={10,7,5}; int *p=arr+1; printf("%d",func(p)+*p); // 答案为5 }
*&p引用的情况:
一开始:
graph LR
classDef className fill:white,stroke:#333,stroke-width:1px;
id3[*&p]-->id1[7]
subgraph arr数组
id[10]-->id1[7]
id1[7]-->id2[5]
end
subgraph *&p
id3[*&p]
end
class id,id1,id2,id3 className;
最后:
graph LR
classDef className fill:white,stroke:#333,stroke-width:1px;
id4[*p]-->id[10]
id3[*&p]-->id[10]
subgraph *&p
id3[*&p]
end
subgraph *p
id4[*p]
end
subgraph arr数组
id[10]-->id1[3]
id1[3]-->id2[5]
end
class id,id1,id2,id3,id4 className;
1 2 3 4 5 6 7 8 9 10 11 12
#include<iostream> using namespace std; int func(int *&p){ return (*p--=3)-1; } int main() { int arr[]={10,7,5}; int *p=arr+1; printf("%d",func(p)+*p); // 答案为12 }
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.