1

I wrote following code I am solving a puzzle I when compiled this part of code

#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++)
 {
 }
}

gives me error

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

Why is the error coming here?

Eitan T
  • 32,660
  • 14
  • 72
  • 109
Registered User
  • 5,173
  • 16
  • 47
  • 73

4 Answers4

7

There's several problems in your code:

  1. You should initialize your arrays in the same line you declare them
  2. You must initialize them with array of numbers, not with array of c-strings:
  3. You actually try to set value to 11'th element of the array.

Correct line of code will be:

int a[10] = {21,33,12,19,15,17,11,12,34,10};
Vladimir
  • 170,431
  • 36
  • 387
  • 313
2

You're setting the eleventh element of the array to an array.

Try this:

int a[10] = {21,33,12,19,15,17,11,12,34,10};
Polynomial
  • 27,674
  • 12
  • 80
  • 107
0
  • Type mismatch: You are setting character literal strings to an ints. This is a no-no.

  • You are accessing one past the end of the array -- a classic off-by-one error.

dirkgently
  • 108,024
  • 16
  • 131
  • 187
0

this is int array don' put qoutes for numbers

c[10]={11,8,3,6,1,4,6,20,19,3};
Rizstien
  • 802
  • 1
  • 8
  • 23