According to C++ Primer, we can provide an initializer on a variable defined as extern, but doing so overrides the extern. An extern that has an initializer is a definition:
extern double pi = 3.1416; // definition
It is also stated in the book that providing an initializer on an extern inside a function is an error. These two statements together are a little confusing in my opinion and they give rise to the following questions in my mind:
If providing an initializer on an extern outside any function can override the extern, why can providing it on an extern inside a function not?
I also don't understand why someone would want to both obtain a declaration adding the extern keyword and provide an initializer. Is it not the same as defining a variable and providing an initializer on it? If it is not, why? Is the answer the reason why we cannot provide an initializer on an extern inside a function?