LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-20-2006, 12:11 AM   #1
ArthurHuang
Member
 
Registered: Jan 2006
Posts: 174

Rep: Reputation: 30
Multi-dimension array problem.


suppose I define a 3D array like " int ***dq;"

Then afte allocate memory to i, I can assign values to it:

for(1D){
for(2D){
for(3D){
dq[i][j][k]= values;

}
}
}

If I pass it as arguments of routines, I write :

fun(dq);
...

Then pass & access it in routine :

void fun(int ***dq){

dq[i][j][k];
}

IT IS CORRECT, IT IS NO PROBLEM!

However, why can't I do this to static array? I mean if I define int brr[i][j][k] and pass it to routine

fun2(brr)

Why can't I write like this:

void fun2( int ***brr){

}

It is wrong
How to pass the argument and access in routines?

Thanks a lot!
 
Old 05-20-2006, 12:59 AM   #2
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
Code:
int globalarray[2][3][4];

void test(int temparray[2][3][4]) {
    int x,y,z;

    for (x=0; x<2; x++) {
        for (y=0; y<3; y++) {
            for (z=0; z<4; z++) {
                printf("temparray[%d][%d][%d]=0x%08X\n",
                    x,y,z,temparray[x][y][z]);
            }
        }
    }
}

int main() {
    memset(globalarray,0,sizeof(globalarray));
    test(globalarray);
    return 0;
}
 
Old 05-20-2006, 09:36 AM   #3
ArthurHuang
Member
 
Registered: Jan 2006
Posts: 174

Original Poster
Rep: Reputation: 30
Thanks a lot! I think too much. It's the basic of programming.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading from a txt file into a two dimension array in C kponenation Programming 3 11-26-2005 07:04 PM
mandriva le 2005 dell dimension 9100 display problem xenophales Mandriva 1 10-10-2005 11:47 AM
Dell Dimension 9100 Ethernet Problem fox83 Linux - Hardware 5 08-19-2005 11:38 AM
Multi-line return from grep into an array? rose_bud4201 Programming 2 06-14-2005 04:11 PM
Working with array of multi-lun troyzeng Linux - General 4 11-15-2003 04:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration