Why does int x[5]; x[0] = 10; is not working. If im doing something wrong i cant figure out what it is.

closed as unclear what you're asking by VE7JRO, gre_gor, KIIV, Mark Smith, per1234 Apr 3 '18 at 22:56

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • You have to specify a size for the array. – Gerben Apr 3 '18 at 19:05
  • i do have now :/ ... – SuperLog GK Apr 3 '18 at 19:11
  • 2
    What does "not working" mean? i.e. What is the context, what do you expect to happen, what is actually happening? – Russell Borogove Apr 3 '18 at 19:12
  • it gives me this error "sketch_apr02b:17: error: 'x' does not name a type" – SuperLog GK Apr 3 '18 at 19:13

Why does int x[]; x[0] = 10; is not working. If im doing something wrong i cant figure out what it is.

Because x[] isn't a valid array.

In C you cannot have variable length arrays. When you create an array you must give it a size.

int x[5]; // Room for 5 entries (numbered 0-4)
x[0] = 10; // Set entry 0 to 10.


You seem to be attempting to put executable code (the assignments) in the global scope along with the variable declaration. Code goes in functions. Not the global scope. For example:

int x[5];

void setup() {
    x[0] = 10;

void loop() {

You can also do direct assignment with constant initialization values at the moment you create the variable:

int x[5] = {10, 3, 2, 6, 2887};
  • well, now i have this: int x[5]; x[0] = 5; and stil not working – SuperLog GK Apr 3 '18 at 19:07
  • Then you have put it in your code wrong. Without seeing your code we can't help you. – Majenko Apr 3 '18 at 19:20
  • there is nothing mutch to see honestly ----- int coords[200][2]; coords[0][0] = 5; coords[0][1] = 5; ----- i have never had this problem before but its not working this time – SuperLog GK Apr 3 '18 at 19:22
  • Show your full code. I won't ask again. – Majenko Apr 3 '18 at 19:23
  • 3
    You cant put code to execute in the global scope. Code goes in functions!!! Also, comments are not the place to post code! EDIT YOUR QUESTION! – Majenko Apr 3 '18 at 19:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.