Skip to content

Commit

Permalink
Exerc 4_14.
Browse files Browse the repository at this point in the history
  • Loading branch information
rsm-lisper committed May 24, 2024
1 parent 30d9c30 commit d8b84c3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions chapter_4.functions_progr_structure/4_14.swap_macro/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BINARY=swap_macro

include ../../Makefile.exerc
17 changes: 17 additions & 0 deletions chapter_4.functions_progr_structure/4_14.swap_macro/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# include <stdio.h>
# include "swap.h"

int main ()
{
char c0 = '0', c1 = '1';
int i0 = 10, i1 = 222;

printf("char: '%c', '%c' => '", c0, c1);
swap(char, c0, c1);
printf("%c', '%c'\n", c0, c1);
printf("int: %d, %d => ", i0, i1);
swap(int, i0, i1);
printf("%d, %d\n", i0, i1);

return 0;
}
11 changes: 11 additions & 0 deletions chapter_4.functions_progr_structure/4_14.swap_macro/swap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ifndef SWAP_H
# define SWAP_H

# define swap(T, X, Y) \
{ \
T c = X; \
X = Y; \
Y = c; \
}; \

# endif
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
char: '0', '1' => '1', '0'
int: 10, 222 => 222, 10

0 comments on commit d8b84c3

Please sign in to comment.