![]() ![]() #include Įrror: variably modified ‘arr’ at file scope ➤ Const cannot be used as a dimension for arrays at global scope while #define can be used. ➤ Const can be passed as call by reference while constant macro could not. It is more likely that #define will not have a symbol, leaving you wondering what it is ➤The debugger’s symbol table contains a symbol for Const, which makes debugging easier. ➤ Const can not use as a case in the switch case statement while macro could be used. ‘ATICLEWORLD’ undeclared (first use in this function). Printf("ATICLEWORLD is %d", ATICLEWORLD) You can see the above code, in which I am able to change the value of the variable.īut what will happen if I use the const keyword with variable? That means const qualifier specifies that a variable’s value is constant and tells the compiler to prevent the programmer from modifying it.Ĭonsider the below example, //iData without const It declares an object to be nonmodifiable. What is the const keyword in C?Ī const keyword is a type qualifier. If you are not familiar with these two fancy words, don’t worry before explaining the difference I will give a small introduction about the C macro (#define) and const qualifier. So I believe these questions have come to your mind What is the difference between macro constants and constant variables in C? How do I best use the const keyword in C? What is the difference between #define and const in C?ĭon’t worry in this blog post, we clear your doubts regarding the constant variable and macro constant with help of programming examples. ![]() Do you have use macro constants and constant variables in your code? If you’re reading this article, then it is likely that you answered yes. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |