常见误区(一)
美容SPA中的一些常见误区和误解 #生活技巧# #化妆美容技巧# #美容SPA知识#
无论是C/C++,还是java,默认情况是值传递,这就造成编写一般意义认为正确的交换两数的方法成为错误的。
C++中可用指针或者引用方式避免
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<iostream>
using namespace std;
void swap1(int a ,int b)
{
int temp;
temp = a;
a = b;
b = temp;
}
void swap2(int &a,int &b)
{
int temp;
temp = a;
a = b;
b = temp;
}
void swap3(int *a,int *b)
{
int temp = *a;
*a = *b;
*b =temp;
}
int main()
{
int swapa = 10;
int swapb = 20;
int swapc = 10;
int swapd = 20;
int swape = 10;
int swapf = 20;
swap1(swapa,swapb);
cout<<"swapa原来10,现在为:"<<swapa<<endl<<"swapb原来20,现在为:"<<swapb<<endl;
swap2(swapc,swapd);
cout<<"swapc原来10,现在为:"<<swapc<<endl<<"swapd原来20,现在为:"<<swapd<<endl;
swap3(&swape,&swapf);
cout<<"swape原来10,现在为:"<<swape<<endl<<"swapf原来20,现在为:"<<swapf<<endl;
system("pause");
}
可以看出直接编写的swap1()方法是无法完成任务的。
但是采用引用或者是指针的形式是行得通的。
网址:常见误区(一) https://klqsh.com/news/view/238309
相关内容
“甲醛”常见的误区“驰名商标”常见误区
性能测试常见误区
宠物养护的常见误区.docx
常见的十大误区
宝宝日常护理:避免常见误区,呵护宝宝健康
时尚界的禁忌:避免常见的穿搭误区
8个常见目标设定误区,你中招了吗
常见的“三高”误区有哪些?
老人常见健身误区有哪些