代码练习——数组与指针

    数组与指针
    
    将指针指向字符串——可以指向常量字符串,也可以指向存储字符串的字符数组

    初始化字符数组时会把静态存储区的字符串拷贝到数组中
    初始化指针时只把字符串的地址拷贝给指针

# include
void  main()
{
    char str[] = "abcdefg";
	char *ptr_str = "abcdefg";
	printf("字符串常量的地址:%p\n","abcdefg");
	printf("字符数组的首地址:%p\n",str);
	printf("字符指针的 取值:%p\n",ptr_str);


    char  names1[5][10] = {"西施","貂蝉","王昭君","杨玉环","赵飞燕"};
	char * names2[10] = {"西施","貂蝉","王昭君","杨玉环","赵飞燕"};

	printf("sizeof names1:%d\n",sizeof(names1));
	printf("sizeof names2:%d\n",sizeof(names2));
}

 

你可能感兴趣的:(C语言基础)