0

So I recently took over a project that has been programmed in a language I am not super familiar with, C. While learning the language, and trying to figure out how this code was put together I noticed something.

In a lot of instances, the person who wrote the code used #define statements to create their variables. For example instead of int width = 5; they'd have #define WIDTH (5).

Is there any real benefit to doing this though?

I need to be very meticulous in how much memory I am using with my program, so do variables created with #define statements use less memory than those created with standard variable declarations?

I can understand wanting to use #define for a constant, since once you've defined it, you can't change it within the program, but is there any other reason to do this? Or is it just bad programming practice?

To boil everything down to a single question:

When and why would I use a statement like #define WIDTH (5) instead of int width = 5;?

Skitzafreak
  • 1,797
  • 7
  • 32
  • 51

0 Answers0