Warm tip: This article is reproduced from stackoverflow.com, please click
c int max variables

How can I write a program to find maximum value of integer variable

发布于 2020-04-13 09:53:25

In C, how can I write a program to find the maximum value of an integer variable? As far as I know the maximum value of an integer variable is 2147483647 but how can I represent this in a C program ?

Questioner
user7023473
Viewed
16
usr 2016-10-19 17:50

As ı know the maximum value of a integer variable is 2147483647

That's a wrong assumption. The maximum value of an int can vary across systems. For example, on a 16-bit machine maximum value of int is not 2147483647.

You don't need to find it yourself. There are pre-defined macros which you can use from <limits.h>. For example, INT_MAX represents the maximum value an int can hold.