How to take the maximum/minimum value of an integer in the C language

Asked

Viewed 2,500 times

4

Talk people! Is there a function in the C language that takes the maximum/minimum value of an integer?

  • 1

    By "maximum value of an integer" you say the largest number that can be represented in an integer?

  • I also understand that you want the lowest and highest possible values to be represented. But I agree that you could have made it a little clearer (not to be confused with the lower/higher value of two integers).

1 answer

7


There is no function, but there are macros defined in the header limits.h of standard library of C. Code example printing minimum and maximum values of an integer:

#include <stdio.h>
#include <limits.h>

int main() {

   printf("Menor valor de um inteiro: %d\n", INT_MIN);
   printf("Maior valor de um inteiro: %d\n", INT_MAX);

   return(0);
}

See spinning in Ideone.

  • 1

    Thanks Master! It worked perfectly!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.