Sunday, July 12, 2009

C++ : Row Major OR Column Major 2D array?

Which type is default in C++ for 2d arrays: Row or Column major. How can I initialize a 2d array by both ways?





Please and Thank You

C++ : Row Major OR Column Major 2D array?
In C++, the 2D arrays are stored in row major order





Visit http://www.daniweb.com/forums/thread2218... for example and http://www.cs.uaf.edu/~cs301/notes/Chapt... for explanation
Reply:If you use loops to initialize the array, change the order of the loops to change the order of initialization.





If you initialize the array when you declare it, the rows will be filled before columns:


int c[2][2] = {1,2,3,4};


- will have 1,2 in the first row and 3,4 in the second.


No comments:

Post a Comment