美文网首页十天学会C语言
第09天C语言(04):指针数组

第09天C语言(04):指针数组

作者: liyuhong | 来源:发表于2017-07-12 22:30 被阅读18次
    二、代码
    #include <stdio.h>
    int main()
    {
        /*
        char str1[] = "lyh";
        char str2[] = "lys";
        char str3[] = "lyt";
        char str4[] = "lyx";
        char strs[4][20] =
        {
            "lyh",
            "lys",
            "lyt",
            "lyx"
        };
        */
        
        char str1[] = "lyh";
        char str2[] = "lys";
        char str3[] = "lyt";
        char str4[] = "lyx";
        
        // 定义数组的格式 : 元素类型 数组名称[元素的个数]
        int a = 10;
        int b = 20;
        int nums[2] = {10,20};
        
        char *names[4] =
        {
            "lyh",
            "lys",
            "lyt",
            "lyx"
        };
        
        for (int i = 0; i < 4; i++) {
            printf("names[%i] = %s\n",i,names[i]);
        }
        
        
        
        return 0;
    }
    

    相关文章

      网友评论

        本文标题:第09天C语言(04):指针数组

        本文链接:https://www.haomeiwen.com/subject/musihxtx.html