##define is a preprocessor directive. So when we define some macro using #define, it will be replaced with its value in the code before compilation. Therefore, when the compiler knows nothing about the code, the macro values are also replaced.
A constant is actually a variable. By declaring this variable, it occupies a memory location. But we cannot directly update the value of a constant type variable. We can change it using some pointer value.
Sometimes programmers may think that using macros is better than const because this does not take up any extra memory space, but with some good compilers, the optimized code will not affect it. They are very similar.
The above is the detailed content of What is the difference between #define and const in C language?. For more information, please follow other related articles on the PHP Chinese website!