Original notes, reproduced please specify the source!
Click "Focus", attention is also a virtue ~
program One:
We know that the subscript of an array cannot be a variable and must be a definite value. To see the program in the C language:
#define a 10
int main ()
{
The first part
int c=20;
int d=10;
int arr[c+d];
Part II
int const A=20;
int const B=10;
int arr[a+b];
return 0;
}
Of course compile errors, because the array subscript cannot be a variable.
See the same program in C + +. There is no difference in C + +, where an array subscript cannot be a variable. Errors are also compiled.
procedure Two :
Continue to see the program changes in the C language:
#define a 10
int main ()
{
The first part
int c=20;
int d=10;
int arr[c+d];
Part II
int const A=20;
int const B=10;
int arr[a+b];
return 0;
}
Compile error found! The cause of the error is consistent with the change!
In other words: in C language , the const definition of a, B is not a constant! Or a variable ! so called " constant variables "!
See the same program in C + +:
int main ()
{
The first part
int c=20;
int d=10;
int arr[c+d];
Part II
int const A=20;
int const B=10;
int arr[a+b];
return 0;
}
Compile through!!!
Conclusion :
C The const modifier in + + is a true constant , and not C in variables ( Read-only ) . C+ + is determined during const-modified constants compilation.
original notes, reproduced please specify the source!
More wonderful please pay attention to the public number: programming according to Law
The const modifier in C + + Note 019:c++ is a true constant