C++: 2D arrays vs. 1D array differences

arrayscmultidimensional-array

I have an array of float rtmp1[NMAX * 3][3], and it is used as rtmp1[i][n], where n is from 0 to 2, and i is from 0 to 3 * NMAX – 1. However, I would like to convert rtmp1 to be rtmp1[3 * 3 * NMAX]. Would addressing this new 1D array as rtmp1[3 * i + n] be equivalent to rtmp1[i][n]? Thanks in advance for the clarifications.

Best Answer

rtmp1[i][n] is equivalent to rtmp1[i*NMAX + n]

See http://www.cplusplus.com/doc/tutorial/arrays/, where your NMAX is their width.