gpt4 book ai didi

c - ‘{’ token c 程序之前的预期表达式

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

我写了下面的代码我在编译这部分代码时正在解决一个难题

#include <stdio.h>
int main ()
{

int a[10],b[10],c[10];
int i,j,k,l;
a[10]={"21","33","12","19","15","17","11","12","34","10"};
b[10]={"10","15","9","13","16","21","15","32","29","7"};
c[10]={"11","8","3","6","1","4","6","20","19","3"};

l=sizeof(a)/sizeof(a[0]);

for (i=0;i<=l;i++)
{
}
}

给我错误

array.c: In function ‘main’:
array.c:7:8: error: expected expression before ‘{’ token
array.c:8:8: error: expected expression before ‘{’ token
array.c:9:8: error: expected expression before ‘{’ token

为什么错误会出现在这里?

最佳答案

您的代码中存在几个问题:

  1. 您应该在声明它们的同一行中初始化您的数组
  2. 您必须使用数字数组而不是 C 字符串数组来初始化它们:
  3. 您实际上尝试将值设置为数组的第 11 个元素。

正确的代码行是:

int a[10] = {21,33,12,19,15,17,11,12,34,10};

关于c - ‘{’ token c 程序之前的预期表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10683147/

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