Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 1
    It might be worth mentioning that all members/elements not being initialised explicitly in this case get initialised to 0 implicitly. Commented May 17, 2015 at 13:50
  • 5
    It is also worth mentioning that this is not standard C. Empty {} are not allowed. (They are for C++) Commented May 17, 2015 at 13:55
  • Which makes this answer simply wrong. There are enough C compilers out there that will flat out reject this as a syntax error. (Even if it's wrong in the question as well, it should be mentioned.) Commented May 17, 2015 at 14:57
  • 1
    Thanks for editing, it looks good (to me, anyway) now. One thing that might be worth covering as well is what @alk hints at too: instead of {3,{0,},{0,}},, you can simply write {3}, or {3,},. But if you prefer it the way you have it now, that's fine too. Commented May 17, 2015 at 16:02
  • Basically I want to do something for each element of the arrays. So currently I'm using a for loop, from 0 to 2, but if the array is empty, I don't want to do anything, and if it only contains 2 elements, I want to do something only 2 times. So I'm initializing the arrays with 3 elements anyway, which leads to some {-1,-1,-1}and {1,2,-1} and I test the value in the for loop and do stuff only if it's different from -1. What is the best way to do this ? Commented May 17, 2015 at 23:49