Get the maximum value of a variable in C

前端 未结 7 1812
感动是毒
感动是毒 2021-02-19 21:33

Is there a function in C that returns the maximum value of a variable like this (I will name the function \"maxvalue\" in example below)?

int a;
printf(\"%d\", m         


        
7条回答
  •  野的像风
    2021-02-19 21:41

    Could easily be done using ANSI C 89:

        #include
        #include
    
    int main(void) {
    
    printf("Max value of char: %d\n", CHAR_MAX);
    printf("Min value of char: %d\n", CHAR_MIN);
    
    printf("Max value of short: %d\n", SHRT_MAX);
    printf("Min value of short: %d\n", SHRT_MIN);
    
    printf("Max value of int: %d\n", INT_MAX);
    printf("Min value of int: %d\n", INT_MIN);
    
    printf("\n\n");
    return 0;
    }
    

    Notice that you can include float.h and then use:

    printf("Max value of Double: %d\n", DBL_MAX);
    

    Though, it is less recommended.

    Good luck, Ron

提交回复
热议问题