What is the difference between static const and const?
For example:
static const int a=5;
const int i=5;
Is there any difference between them?
When would you use one over the other?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The difference is the linkage.
If the
iobject is not used outside the translation unit where it is defined, you should declare it with thestaticspecifier.This enables the compiler to (potentially) perform further optimizations and informs the reader that the object is not used outside its translation unit.