Linux:打印常量字符串指针数组和字符串指针数组和地址

代码:

#include
#include
#include
#include
#include
#include

void main()
{
//常量字符串指针数组
char *ch1 = “hello”;
char *ch2 = “world”;
char *ch3 = “nihaonihao”;

char *ch[] = {ch1, ch2, ch3};

printf("ch[0][0]: %p\n", &ch[0][0]);
printf("ch addr: %p\n", &ch);

//字符串指针数组
char ch11[] = "hello";
char ch12[] = "world";
char ch13[] = "nihao";
char *ch10[] = {ch11, ch12, ch13};
printf("ch10[0][0]: %p\n", &ch10[0][0]);
printf("ch10 addr: %p\n", &ch10);

printf("\n");

int i;

for (i = 0; i < 3; i++)
{
    while (*(ch[i]))
    {
        printf("%c", *(ch[i]));
        ch[i]++;
    }
    printf("\n");
}

printf("\n");

for (i = 0; i < 3; i++)
{
    while (*(ch10[i]))
    {
        printf("%c", *(ch10[i]));
        ch10[i]++;
    }
    printf("\n");
}

printf("\n");

}

结果:

Linux:打印常量字符串指针数组和字符串指针数组和地址_第1张图片

你可能感兴趣的:(linux,c++,c语言)