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.

4
  • 3
    sizeof(vec) won't work like you think it will. Arrays degrade to pointers when passes as a function, so that line will be the same as sizeof(int *) - not what you want. Commented Oct 13, 2009 at 3:41
  • Also, is there any reason not to go ahead and make it a real two-dimensional array? Commented Oct 13, 2009 at 3:43
  • Chris: You are right. Thanks for pointing it out. A correct way would be passing and additional parameter sizeof(vec)/sizeof(vec[0]) as the size of the vec. Commented Oct 13, 2009 at 12:48
  • Since you changed int[] grid to int *grid you can as well use a static initializer in C99 and forget all the nonsense above: struct Grid testgrid = {1, 3, (int[3]){4, 5, 6}}; (sorry for reviving but this trivial solution should be mentioned ...) Commented Feb 6, 2012 at 15:17