S
shawn
As far as i know, keyword "const" is invented to replace "define" identifier.
But ...
test1.c
------------------------------
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
const int MAX_CHAR_NUM=10;
char name[MAX_CHAR_NUM]="Computer";
printf("My name is %s.\n", name);
exit(EXIT_SUCCESS);
}
test2.c
-----------------------------
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
enum width {MAX_CHAR_NUM=10, OTHER};
char name[MAX_CHAR_NUM]="Computer";
printf("My name is %s.\n", name);
exit(EXIT_SUCCESS);
}
why test2.c can be compiled and test1.c not?
And what's the difference between c const and c++ const?
Thanks.
But ...
test1.c
------------------------------
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
const int MAX_CHAR_NUM=10;
char name[MAX_CHAR_NUM]="Computer";
printf("My name is %s.\n", name);
exit(EXIT_SUCCESS);
}
test2.c
-----------------------------
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
enum width {MAX_CHAR_NUM=10, OTHER};
char name[MAX_CHAR_NUM]="Computer";
printf("My name is %s.\n", name);
exit(EXIT_SUCCESS);
}
why test2.c can be compiled and test1.c not?
And what's the difference between c const and c++ const?
Thanks.