Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
write a C or C++ program to access a 2D array column wise and row wise
Posted
Comments
Sergey Alexandrovich Kryukov 27-Jan-15 16:51pm    
What does it mean, exactly?
—SA

1 solution

First thing to understand is this: due to the nature of C/C++ arrays, "2D" array is no different from "1D" array, as well as the array of any other rank. The indexing of an array element (of a non-jagged array) using multiple indices is not more that syntactic sugar. The same very array can be considered as "2D" or "1D". Please see:
http://www.cplusplus.com/doc/tutorial/arrays[^].

Pay attention for the chapter "Multidimensional arrays".

See also: http://en.wikipedia.org/wiki/Syntactic_sugar[^].

This way, the access to array is neither row-wise nor columns-wise. It is always "element-wise". Change one of the two indices and keep another index constant, and you move along one column, change another, and you move along one row. (Or visa versa: it depends on what you call row and columns. :-))

—SA
 
Share this answer
 
v2
Comments
Andreas Gieriet 27-Jan-15 17:02pm    
My 5.
Cheers
Andi
Sergey Alexandrovich Kryukov 27-Jan-15 17:43pm    
Thank you, Andi.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900