我试图使用指针实现一个字符串数组.以下是我的代码.
#include <stdio.h>
const int MAX = 4;
int main () {
char *names[] = {
"abcd",
"efgh",
"ijkl",
"mnop",
};
int i = 0;
for ( i = 0; i < MAX; i++) {
printf("Value of names[%d] = %s\n", i, names[i] );
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我在运行时发出警告.以下是警告:
C:\workspace>g++ test_pointer_string_arr.c -o tpsa.exe
test_pointer_string_arr.c: In function 'int main()':
test_pointer_string_arr.c:12:4: warning: deprecated conversion from string const
ant to 'char*' [-Wwrite-strings]
};
^
test_pointer_string_arr.c:12:4: warning: deprecated conversion from string const
ant to 'char*' …Run Code Online (Sandbox Code Playgroud)