I am teaching myself C by going over my C++ book and recoding the problems in C. I wanted to know the correct industry standard way of declaring variables constant in C. Do you still use the #define directive outside of main, or can you use the C++ style const int inside of main?
Share
constin C is very different toconstin C++.In C it means that the object won’t be modified through that identifier:
Also, unlike C++, const objects cannot be used, for instance, in switch labels:
So … it really depends on what you need.
Your options are
#define: really const but uses the preprocessorconst: not really constenum: limited tointlarger example