Click here to Skip to main content
15,877,168 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
Hello Friends,

Can anybody tell me that how are we send the particular element of multi-dimensional array?

My condition is as below:
I have a two dimensional array
C++
m_pJGraphicSurface[2][4];

All element of this array is filled with values. Now I want to send the first four element of first row at a time and then next four means
C++
m_pJGraphicSurface[i][All_Four_Element].

How can we do this in vc++?
Please help me to resolve this.
Thanks
Posted
Comments
Richard MacCutchan 13-Jun-13 8:55am    
Send it where? If you want to use it as a parameter to a function, then just send the pointer to the row: m_pJGraphicSurface[i].
Vaibhav_J_Jaiswal 17-Jun-13 4:26am    
By sending array in this way, can I used the above row by breaking it into four element i.e. when I called the function I am sending a row and in function definition I am using each element of that row. How it is possible please tell me by giving example?

Richard is right. It's a it unusual but you can do it.

JGSurface m_pJGraphicSurface[2][4];

JGSurface* pFirstRow = m_pJGraphicSurface[0];
JGSurface* pSecondRow = m_pJGraphicSurface[1];



It's unusual because if we only have 2 of something and that is a constant then they are very often just given two separate variable names, like FirstRow and SecondRow rather than being tied together in one array unless that's needed for other reasons. Even if the memory needs to be all together that can be achieved with a struct e.g.

struct GraphicSurfaces
{
  JGSurface FirstRow[4];
  JGSurface SecondRow[4];
};


It's a matter of style and of course what you need to achieve.
 
Share this answer
 
Comments
Vaibhav_J_Jaiswal 17-Jun-13 4:27am    
By sending array in this way, can I used the above row by breaking it into four element i.e. when I called the function I am sending a row and in function definition I am using each element of that row. How it is possible please tell me by giving example?
I do one thing. Send the row and the count of the element in each row.Make one loop in called function and get each element of the sent row. Now do what ever I want and store it on same count.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 24-Feb-14 3:22am    
This "answer" is fake, as well as some of your other "answer". Please stop it.
—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