MIPI_BaseC_WebinarFRTK/25_Seminar12/04_macros_swap_p13.c

16 lines
289 B
C
Raw Normal View History

2024-11-13 09:22:28 +03:00
#include <stdio.h>
2024-11-14 08:39:22 +03:00
#define SWAP(type,a,b) do {type a##1 = a; a = b; b = a##1;}while(0)
2024-11-13 09:22:28 +03:00
int main(void)
{
2024-11-14 08:39:22 +03:00
int a=5, t=7;
printf("a = %d b = %d\n", a, t);
if (a<t)
SWAP(int, a,t);//{...}
2024-11-13 09:22:28 +03:00
else
a = 1000;
2024-11-14 08:39:22 +03:00
printf("a = %d b = %d\n", a, t);
2024-11-13 09:22:28 +03:00
return 0;
}