请参阅下面的示例,其中我将交换两个变量的值。 do-while(0)结构很不错
#include <stdio.h>
#define swap(x,y,T) do { \
T temp = (*x);\
(*x) = (*y); \
(*y) = temp; \
} while (0)
int main(void)
{
int a = 5;
int b = 9;
printf("Value of a and b before swaping\n");
printf("a = %d\n",a);
printf("b = %d\n",b);
//Swap the number
swap(&a,&b,int);
printf("\n\nValue of a and b After swaping\n");
printf("a = %d\n",a);
printf("b = %d\n",b);
return 0;
}