Programming/C++
[C] Macro, Constant, Preprocessor
OKOK
2017. 3. 29. 10:29
/*------------------------------------------------------------------------------------------
@ Pratice C laguage
Author : SAM
Created : 29-03-2017
Modified : 29-03-2017
Language/ver : C in MSVS2015
Description : Practice
KEYWORD : Macro, Constant, Preprocessor
------------------------------------------------------------------------------------------*/
#include<stdio.h>
#define SQUARE(x) x*x
int main(void) {
int a;
float d;
printf("Input a number(int) : ");
scanf_s("%d", &a);
printf("Sqare of %d : %d\n", a, SQUARE(a));
printf("INputer a number(float) : ");
scanf_s("%f", &d);
printf("square of %f : %f \n", d, SQUARE(d));
return 0;
}
1. 자료형에 독립적이다.
2. 작은 함수는 매크로 처리하면 효율적이다. 단순 치환이므로.