c - How are getchar() and putchar() Macros? -
from understand macros in c, predefined constants used throughout program constant value, go ahead , define them avoid further complications , make code more readable, people reading understand supposed stay constant , isn't.
i have read here , there (c programming modern approach, k.n king) can define these 2 functions macro.
since i'm new c, can't wrap head around how can these 2 defined macro?
there 2 types of macros: simple substitution macros , function-like macros.
substitution macros replace 1 instance of symbol another. example:
#define len 10 char str[len]; after preprocessing, becomes:
char str[10]; a function-like macro can take parameters can plugged in whatever gets substituted:
#define max(a,b) ((a) > (b) ? (a) : (b)) int x = max(2,3); after preprocessing:
int x = ((2) > (3) ? (2) : (3)); in case of getchar , putchar, can defined follows:
#define getchar() getc(stdin) #define putchar(c) putc(c, stdout)
Comments
Post a Comment