In find.c, there's a conditional that references a constant called "INT_MAX". I looked through all the pset files and couldn't find any reference to this constant. What is it, what does it represent, and where is it defined?

  • INT_MAX is already defined in the standard c library file limits.h. if u use linux check /usr/include folder and find the header file limits.h.It has a value of 2147483647
    – user2287
    Aug 26, 2014 at 12:50

1 Answer 1


INT_MAX is defined in limits.h, which is a standard C header.

INT_MAX: Maximum value for an object of type int (32767 or greater)

You may wonder why find.c needs that?

   int straw = GetInt();
   if (straw = INT_MAX)

If you look at cs50.c (which defines GetInt()), you'll see that GetInt() returns INT_MAX when it doesn't receive an integer:

// get line of text, returning INT_MAX on failure
    string line = GetString();
    if (line == NULL)
        return INT_MAX;

So, find.c uses INT_MAX to recognize that GetInt() received a NULL line (ie, the user ended the entry).

  • 1
    I can't see "limits.h" in anywhere of the codes. Where is it defined, could you please help?
    – user3310
    Dec 25, 2014 at 12:38
  • 1
    Figure out that it is actually defined inside cs50.h, now it is all clear.
    – user3310
    Dec 25, 2014 at 12:46
  • "you'll see that GetInt() returns INT_MAX when it doesn't receive an integer:" So you meant non-integer as ctrl-d(eof) !?
    – user10784
    May 4, 2016 at 12:03
  • yes. exactly that.
    – curiouskiwi
    May 4, 2016 at 23:37
  • INT_MAX is stated in : reference.cs50.net/cs50.h/GetInt
    – aguy01
    Jun 10, 2016 at 16:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .