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

标签 c syntax-error

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

#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/

相关文章:

c - 需要帮忙进行数组赋值

c - 这在c中是什么意思? char *array[]= { "**", "**", "**"};

c - 对 'funtion_name' 的 undefined reference

c - 根据变量的地址将变量存储在哪里(数据段或堆或BSS)?

c++ - cpp中的assert.h有什么用?

java - 语法错误: insert to complete classbody and mainclass

makefile 缺少分隔符

Java 问题 : is float not allowed to be declared as final?

mysql - 在使用我的 where 函数进行数学运算时,我的 mysql 查询出现语法错误

"with"语句的 Python 无效语法