-
Notifications
You must be signed in to change notification settings - Fork 1
/
14.c
39 lines (32 loc) · 873 Bytes
/
14.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
/**
* Using a block structure removes warnings and allow us to use the same macro
* with different types without redeclaring '_z' variable.
*/
#define swap(t, x, y) { t _z = x; x = y; y = _z; }
main()
{
/**
* Using separate scopes so we can put declarations after function calls.
* ISO C90 forbids it and I don't wanna declare all variables
* at the beginning of main. :D
*/
{
int a = 10, b = 20;
printf("[*] %d %d\t=>\t", a, b);
swap(int, a, b);
printf("%d\t%d\n", a, b);
}
{
float c = 35.62, d = 012.51;
printf("[*] %g %g\t=>\t", c, d);
swap(float, c, d);
printf("%g\t%g\n", c, d);
}
{
char i = '^', j = '~';
printf("[*] '%c' '%c'\t=>\t", i, j);
swap(char, i, j);
printf("'%c'\t'%c'\n", i, j);
}
}