+ 4

=>>What is the difference between '#define' and 'const int (global)' in C++ ?

#define PI 3.14 const float PI 3.14 What is the difference between these two ??

11th Sep 2018, 1:14 PM
Alpha Rays
Alpha Rays - avatar
1 Odpowiedź
+ 10
#define is a preprocessor directive/macro that will replace every "PI" in your code with 3.14 before it is compiled. So by the time the code is compiled, there is no variable/constant "PI" in your code anymore and the compiler has no idea what "PI" is. All it "sees" is 3.14. const float on the other hand defines a constant. It's like a regular variable, but it can't be changed.
11th Sep 2018, 1:39 PM
Anna
Anna - avatar