Share via


__min

傳回兩個值的較小預處理器宏。

語法

#define __min(a,b) (((a) < (b)) ? (a) : (b))

參數

a, b
運算子運作的任何類型 < 值。

傳回值

兩個引數的較小引數。

備註

__min 巨集比較兩個值並傳回較小值。 引數可以是帶正負號或不帶正負號的任何數值資料類型。 引數和傳回值必須屬於相同的資料類型。

傳回的引數會由宏評估兩次。 如果引數是評估其值時改變其值的運算式,則雙重評估可能會導致非預期的結果,例如 *p++

需求

常式 必要的標頭
__min <stdlib.h>

範例

// crt_minmax.c

#include <stdlib.h>
#include <stdio.h>

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 ) );
}
The larger of 10 and 21 is 21
The smaller of 10 and 21 is 10

另請參閱

數學和浮點支援
__max