Now, bear with me, I'm new to c++. While following an online tutorial for c++, it mentioned that all #define is used for is to define a constant, like this.
#define RANDOM_CONSTANT 288 What I'm confused about is, why can't it just be done by creating a variable like this?
int RANDOM_CONSTANT = 288; Does #define have any other applicable uses other than defining constants?
definefor constants to improve readability. Later on down the page, it goes into other uses as well. Ok, that's fine.int const RANDOM_CONSTANT = 288;. In early versions of C that wasn't possible and#definewas the best option. C++ chose (probably for practical reasons) to use the same preprocessor as C.const int RANDOM_CONSTANT = 288;to make the name a constant expression. But as inetknght's answer points out, that doesn't let you use it in a#ifexpression.