const int array[] = {1,2};
const int array[2] = {1,2};
Both compile and work with no problems. Is there any difference in these ?
(I use Codevision, but that shouldn't really matter)
const int array[] = {1,2};
const int array[2] = {1,2};
Both compile and work with no problems. Is there any difference in these ?
(I use Codevision, but that shouldn't really matter)
No, there is no difference.
The only exception is for the 2nd case if one initialises a
char
array with a string literal and the array's size does not reflect the'\0'
-terminator, then the latter gets chopped off.For all other types or kinds of initialisation the compiler should warn about a too large initialiser.
If the initialiser is "smaller" then the array, the remaining elements are initialised as if they were defined at globale scope, that is as if they were
static
.All this is completely unrelated to whether anything in this context is
const
or not.