logo

Macros with parameters in C

#include <stdio.h> #include <stdlib.h> #include <string.h> #define PRINT_VAR(X)\ printf(#X " is %d at address %p\n, X, &X); #define SWAP(A, B) A ^= B ^= A ^= B; int main(int argc, char* argv[]) { int a = 3; PRINT_VAR(5); int x = 2, y = 5; printf("%d %d\n", x, y); SWAP(x, y); printf("%d %d\n", x, y); return 0; }
Course thumb

The C programming language made simple