c - 错误: expected expression before ‘=’ token

标签 c arrays operators

这是我收到的错误:

c:17:15: error: expected expression before ‘=’ token
             suma + = mat[N][M];

这是我的代码:

#include<stdio.h>
#define N 3
#define M 3

int mat[N][M]i,j,k,l,m,n;
int vector[N];
int suma; 

int main (void){
   for(i=0;i<N;i++){
     for(j=0;j<M;j++){
       printf("Enter a number: ");
       scanf("%d", &mat[N][M]);
     }
   }
   for(k=0;k<N;k++){
      suma=0;
     for(l=0;l<M;l++){
       **suma+ = mat[N][M];
     }
     vector[i]=suma;
   }
   return 0;
}

最佳答案

+=   !=   + =

含义:只需写:suma += mat[N][M];
......................................^ 没有空间。

为了完整起见,我将添加 Sourav 提到的内容: 您需要在第一个 for 循环后重置 i (i=0),以避免访问越界内存并导致未定义的行为。

关于c - 错误: expected expression before ‘=’ token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34964902/

相关文章:

c - 像 C 中的 NSTimer 一样重复函数调用

c++ - 函数应用关联到左边

php - 类似于 MySQLi 的 PDO 获取数组

c# - 获取控制数组中的控制索引

c# - "I"运算符,非整数和非 bool 类型除外

c++ - 将运算符>>重载到 C++ 中的字符缓冲区 - 我可以告诉流长度吗?

c - 按其中一个字符串值的字母顺序对结构数组进行排序的函数

c - 为什么数据结构的大小通常为 2^n?

c - 在c中的PATH环境中搜索应用程序

arrays - 将数据从 Firebase 读取到数组中