반응형
1. #if 매크로
#if 값
문장
#endif
값이 0이 아닐 경우 문장 실행
#include <stdio.h>
int main()
{
#if 3
printf("hi");
#endif
return 0;
}
2. #ifdef 매크로
#ifdef 매크로이름
문장
#endif
매크로 이름이 #define 되었을 경우 문장 실행
#include <stdio.h>
int main()
{
#define A
#ifdef A
printf("hi");
#endif
return 0;
}
3. #ifndef 매크로
#ifndef 매크로이름
문장
#endif
매크로 이름이 #define 되지 않았을 경우 문장 실행
#include <stdio.h>
int main()
{
#define B
#ifndef A
printf("hi");
#endif
return 0;
}
반응형
'C언어 > 매크로 (#define)' 카테고리의 다른 글
[C언어] #define 매크로에서 괄호가 중요한 이유 (0) | 2022.07.28 |
---|---|
[C언어] #define 이란 무엇인가 (왜 매크로라고 부르나) (0) | 2022.07.27 |
댓글