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 |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |