What is the difference between const and #define in C?
| const | #define |
|---|---|
| Has a data type | No data type, only text |
| Handled by the compiler | Handled by the preprocessor |
| Follows scope rules | Valid from the line it is written |
| Has a memory address | No address |
Example: const int MAX = 10; and #define MAX 10. Prefer const (or enum) for plain values, because it is safer. See C Constants.
Learn more about the similar topics:
| Tutorials |
|---|
| C Preprocessor and Macros |
| C File Handling |
| C Read From a File |
| C Command Line Arguments |
| Exercises & Assignments |
|---|
| No Content Found. |