#include <stdio.h>
int main(){
char *params[][2] = {
{"age", "18"},
{"name", "小明"},
{"address", "beij"},
{"", ""}
};
printf("%s\n", params[0][0]);
return 0;
}
I don’t quite understand
Each array element is a string. You need to use char *
when defining a string. Do you understand this?
When you define a string, you use char *a = "test";
right,
then when you define a string array, the elements in the array are Not all should be of the char *a = "test";
對(duì)吧,
那么當(dāng)你定義一個(gè)字符串?dāng)?shù)組的時(shí)候,數(shù)組內(nèi)的元素是不是應(yīng)該都是char *
type.
This is defining a string, you can view char *
當(dāng)成char
as char
(of course this is wrong, but in this case it will be better understood).
Or look at it like this, typedef char * string
, then the definition becomes like this:
string params[][2] = {
{"age", "18"},
{"name", "小明"},
{"address", "beij"},
{"", ""}
};