linux - How to understand such a pointer in C language?
巴扎黑
巴扎黑 2017-05-16 13:25:35
0
1
559
#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

巴扎黑
巴扎黑

reply all(1)
淡淡烟草味

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";对吧,
那么当你定义一个字符串数组的时候,数组内的元素是不是应该都是char * type.

This is defining a string, you can view char *当成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"},
    {"", ""}
};
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!