#include <iostream> using namespace std; struct A{ int a; int b; }A1={0}; struct A my_swap(int a1,int b1) { A1.a=b1; A1.b=a1; return A1; } int main() { int a=1,b=2; A A2= my_swap(a,b); my_swap(a,b); printf("%d %d",a,b); return 0; }
用结构体实现了swap
其实最简单的还是用指针来写swap
my_swap(int &a,int &b) my_swap(int *a,int *b) /× 两种写法等价
然而直接用
my_swap(int a,int b); 是不能交换函数值的
因为虽然在这个函数虽然在这个函数内部互换了函数值,但是这仅仅局限与函数内部,对于整个main函数的调用并没有使用返回值。
我在想如果用内联函数进行展开是不是可以交换呢。读者们可以亲自试试。 inline int swap(int a,int b);
十一月 | ||||||
---|---|---|---|---|---|---|
日 | 一 | 二 | 三 | 四 | 五 | 六 |
27 | 28 | 29 | 30 | 31 | 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
2022年8月09日 19:26
BSNL Personalized Ring Back Tone services, a mobile subscriber greet their callers with their favorite song as best choice, and this new My BSNL Tunes App service is an innovative service help the subscribers to express themselves, access information, entertainment and connect the other by greeting. BSNL Tune Most popular albums are vying for honor, but to find the best with codes or by names it is difficult, but now with this new launch of My BSNL Tunes App, each mobile user now have a chance to listen and activate their favorite songs of any language to set as BSNL caller tune on their mobiles.
2023年1月23日 20:12
This swap function is quite an impressive extension! It provides an effective and efficient way to rearrange data within various data structures. It is sure to be a great real estate services Smithfield asset for any programmer, making the process of organizing data a much simpler task. Thanks to this expansion, it will be much easier to modify and store data!