0

What does the following code do in the find.c source code in pset3

const int MAX = 65536;

Does it define a constant MAX with value 65536?

If so, then is this same as writing : #Define MAX 65536

1 Answer 1

1

No they are not the same:

  • #define MAX 65536: This tells the compiler to swap all instances of MAX with 65536, it is not not a variable that exists in memory.

  • const int MAX = 65536: This declares a variable MAX of type int that contains the value 65536, the const keyword tells the compiler that this variable must not and will not be changed, its value is constant for the remainder of its lifetime.

You might want t have a look the links below for more detailed info on this topic.

  1. When and for what purposes should the const keyword be used in C for variables?
  2. Wikipedia on const
  3. Which is better; const int vs #define?

You must log in to answer this question.

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