
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between #define and const in C
The #define is preprocessor directives. So when we define some macro using #define, it replaces into the code with its value before compilation. So when the compiler does not know anything about the code, in that time also the macro values are replaced.
The constant is actually a variable. By declaring this variable, it occupies memory unit. But we cannot update the value of constant type variable directly. We can change it using some pointer values.
Sometimes programmer may think that using macro is better than const, as this is not taking any additional space into the memory, but for some good compilers, the optimized code will not affect. They are very similar.
- Related Questions & Answers
- Difference between #define and const in Arduino
- What is the difference between #define and const Keyword in C++?
- Difference between const int*, const int * const, and int const * in C/C++?
- Difference between const int*, const int * const, and int const * in C
- Difference between const char* p, char * const p, and const char * const p in C
- Difference between readonly and const keyword in C#
- What is the difference between const int*, const int * const, and int const *?
- Difference Between Static and Const in JavaScript
- Explain the difference between const and readonly keywords in C#
- enum vs. const vs. #define in C/C++
- What is difference between int and const int& in C/C++?
- What is the difference between keywords const and readonly in C#?
- Compare define() vs const in PHP
- What is the main difference between Object.freeze() and const in JavaScript?
- What is the difference between "const" and "val" in Kotlin?
Advertisements