What is the difference between const and #define in C?

const#define
Has a data typeNo data type, only text
Handled by the compilerHandled by the preprocessor
Follows scope rulesValid from the line it is written
Has a memory addressNo 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.