gpt4 book ai didi

c - 初始化字符串数组

转载 作者:太空狗 更新时间:2023-10-29 16:23:18 26 4
gpt4 key购买 nike

初始化 char** 的正确方法是什么?我收到覆盖错误 - 尝试时读取未初始化的指针 (UNINIT):

char **values = NULL;

char **values = { NULL };

最佳答案

此示例程序说明了 C 字符串数组的初始化。

#include <stdio.h>

const char * array[] = {
"First entry",
"Second entry",
"Third entry",
};

#define n_array (sizeof (array) / sizeof (const char *))

int main ()
{
int i;

for (i = 0; i < n_array; i++) {
printf ("%d: %s\n", i, array[i]);
}
return 0;
}

打印出如下内容:

0: First entry
1: Second entry
2: Third entry

关于c - 初始化字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21023605/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com