3 ms·
C supports multidimensional arrays. https://learnxinyminutes.com/docs/c/ https://learnxinyminutes.com/docs/c/ then text seach for "dimensional". More detail:
by drivers99 10y ago
C supports multidimensional arrays.
https://learnxinyminutes.com/docs/c/ https://learnxinyminutes.com/docs/c/ then text seach for "dimensional".
More detail: http://beginnersbook.com/2014/01/2d-arrays-in-c-example/ http://beginnersbook.com/2014/01/2d-arrays-in-c-example/
- graycat 10y agoThanks. I didn't see that in K&R, 1988. Are such multi-dimensional arrays new since 1988? When I needed to do a little matrix work in C, I just wrote my own little package of matrix code, maybe with more functionality than I just saw in your first link. Maybe I didn't really need to write my own?
- drivers99 10y agoI'm not sure. I only started learning C around 1991. I could see how you might still have to work around using the arrays. "a[4][4]" as an example allocates memory contiguously, but if you pass a pointer to a, you lose the dimensionality (it's more like "a[16]"). So you'd have to have some other way to pass the dimensions in and you'd have to calculate the location of elements yourself. Otherwise, you'd have to pass it by value (if the dimensions are known at compile time and don't change) which can be very inefficient (copying large blocks of memory). I thought maybe you were getting at that when you said C doesn't "really" support it. The more I look into how to pass a multi-dimensional array around in C, the more I think you are more right than I was. It doesn't really have it, it's more like a "recursive use of the type system" as one link was explaining it.