gpt4 book ai didi

c - 在 C 中没有全局变量或更改函数输入的情况下对函数内部数组的变量赋值

转载 作者:太空宇宙 更新时间:2023-11-04 07:52:26 25 4
gpt4 key购买 nike

我有一组特定的约束。如果没有约束,这个问题并不难。

    #define ROW 12
#define COL 6

int main (void)
{
// Code can be changed in brackets
char arr[ROW][COL];
function1(arr);
printf("%s", arr[0][0]);
}


void function1(char arr[][COL]){ //Can't change anything in this line
// Code allowed to be changed inside brackets
// Trying to assign values to multi-dim array as shown below
arr[0][0] = 'O';
}

Process finished with exit code -1073741819 (0xC0000005)

最佳答案

更改arr[0][0] = "O";arr[0][0] = 'O';

printf("%s", arr[0][0]); //<-----should be %c 中指定正确的格式

#define ROW 12
#define COL 6

int main (void)
{
// Code can be changed in brackets
char arr[ROW][COL];
function1(arr);
printf("%c", arr[0][0]); //<----------- should be %c
}


void function1(char arr[][COL]){ //Can't change anything in this line
// Code allowed to be changed inside brackets
// Trying to assign values to multi-dim array as shown below
arr[0][0] = 'O';
}

关于c - 在 C 中没有全局变量或更改函数输入的情况下对函数内部数组的变量赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52995312/

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