Difference between #define and const???
CBSE, JEE, NEET, CUET
Question Bank, Mock Tests, Exam Papers
NCERT Solutions, Sample Papers, Notes, Videos
Posted by Maitryee Gol 3 years, 5 months ago
- 1 answers
Related Questions
Posted by Kandeepan Jothivel 6 months, 4 weeks ago
- 2 answers
Posted by Hanni Pham 4 months, 2 weeks ago
- 0 answers
Posted by Syedali Fathima 5 months, 3 weeks ago
- 1 answers
Posted by Priya Shukla 5 months, 3 weeks ago
- 1 answers
Posted by Prawar Narang 6 months, 2 weeks ago
- 1 answers
Posted by Hanni Pham 4 months, 2 weeks ago
- 1 answers
Posted by Manoj Kumar Manoj Kumar 7 months, 2 weeks ago
- 0 answers
myCBSEguide
Trusted by 1 Crore+ Students
Test Generator
Create papers online. It's FREE.
CUET Mock Tests
75,000+ questions to practice only on myCBSEguide app
Sia ? 3 years, 5 months ago
Const is a declaration of constant, compiler will do appropriate checks during the compile time
#define is a macro compiler will see a value.
Speaking in terms of memory const declaration could be more efficient:
const short x =3D 1;=20
// this will allocate 16 bits for x (actually it depends on the machine, I assume unix platform with 32 bits integers)
#define x (short)1=20
// this will probably allocate 32 bits to hold the constant 1.
Use const instead of #define mainly because of compiler checks. And inline functions instead of macros as well. Preprocessor is the obsolete remnant from early C days, there’s no use of it in the oop environment.
0Thank You