宏#define命令练习
#include <stdio.h>
#include <stdlib.h>
#define exchange(a,b) {\
int t;\
t = a;\
a = b;\
b = t;\
}
int main(){
int x = 10;
int y = 20;
exchange(x, y);
printf("x = %d, y = %d\n", x, y);
system("pause");
return 0;
}
宏#define命令练习(2)
#include <stdio.h>
#include <stdlib.h>
#define big >
#define equ ==
#define sma <
int main(){
int a = 10;
int b = 20;
if (a big b){
printf("a > b\n");
}
else if(a equ b){
printf("a = b\n");
}
else if(a sma b){
printf("a < b\n");
}
else {
printf("ERROR!\n");
}
system("pause");
return 0;
}
学习使用按位与(&)
在二进制位下进行运算,同1则1,否则为0.
#include <stdio.h>
#include <stdlib.h>
int main(){
int a = 10;
int b;
b = a & 11;
printf("%d\n", b);
b &= 2;
printf("%d\n", b);
system("pause");
return 0;
}