C++ 매크로 MIN(), MAX()

1 개요[ | ]

C언어 매크로 MIN(), MAX()
C언어 #define MIN(), MAX()
#define	MIN(a,b) (((a)<(b))?(a):(b))
#define	MAX(a,b) (((a)>(b))?(a):(b))
#define __min(a,b) (((a)<(b))?(a):(b))
#define __max(a,b) (((a)>(b))?(a):(b))

2 사용예시[ | ]

#include <iostream>
#define	MIN(a,b) (((a)<(b))?(a):(b))
#define	MAX(a,b) (((a)>(b))?(a):(b))
using namespace std;

int main() {
    int a = 11;
    int b = 1;
    int c = 12;
    int d = 2;
    cout << MIN(MIN(a, b), MIN(c, d)) << endl; // 1
    cout << MAX(a, MAX(b, MAX(c, d))) << endl; // 12
}
#include <stdio.h>
#define __min(a,b) (((a)<(b))?(a):(b))
#define __max(a,b) (((a)>(b))?(a):(b))

int main( void )
{
   int a = 10;
   int b = 21;

   printf( "The larger of %d and %d is %d\n",  a, b, __max( a, b ) );
   printf( "The smaller of %d and %d is %d\n", a, b, __min( a, b ) );
}

3 같이 보기[ | ]

4 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}