可能没啥用的C语言的tips

不用分号输出hello world

Solution: 1
void main(){
 if(printf("Hello world")){
 }
}

Solution: 2
void main(){
 while(!printf("Hello world")){
 }
}

Solution: 3
 void main(){
 switch(printf("Hello world")){
 }
}

不引入临时变量交换两个值

#include
int main(){
 int a=5,b=10;
//process one
 a=b+a;
 b=a-b;
 a=a-b;
 printf("a= %d b= %d",a,b);

//process two
 a=5;
 b=10;
 a=a+b-(b=a);
 printf("\na= %d b= %d",a,b);

//process three
 a=5;
 b=10;
 a=a^b;
 b=a^b;
 a=b^a;
 printf("\na= %d b= %d",a,b);

//process four
 a=5;
 b=10;
 a=b-~a-1;
 b=a+~b+1;
 a=a+~b+1;
 printf("\na= %d b= %d",a,b);

//process five
 a=5,
 b=10;
 a=b+a,b=a-b,a=a-b;
 printf("\na= %d b= %d",a,b);
 return 0;
}

你可能感兴趣的:(c/c++,c语言)