嵌入式 常见面试问题

1.如何在不使用第三个变量的情况 下交换变量值?

方法1
int a = 3;
int b = 4;
a = a+b; //7
b = a-b; //3
a = a-b; //4
方法2,
int a = 3;
int b = 4;
a = a^b;
b = a^b;
a = a^b;
方法3
int a = 3;
int b = 4;
a = b+(b=a)*0;

2.

posted @ 2017-06-05 17:33  china_sdd  阅读(156)  评论(0编辑  收藏  举报