Formal Argument for int Array[x][y]?

E

erktek

Hi!
It is clear that when we try to pass a one dimentional array to a
function
we use int* such as


void display(int *LocalAarray)
{
......
}

int main(void)
{
int MainArray[3] = {1, 2, 3};

display(MainArray);
return 0;
}
name of the array is automaticly casted to (int*)
but what is the case I want to use two dimensional array ?
int main(void)
{
int MainArray[2][3] = {{1, 2, 3},
{4,5,6}};

display(MainArray);

return 0;
}

what should be the formal parameter of display function?
void display(int** Local Array) ? <-- Is it true?
 
S

Skarmander

Hi!
It is clear that when we try to pass a one dimentional array to a
function
we use int* such as


void display(int *LocalAarray)
{
......
}

int main(void)
{
int MainArray[3] = {1, 2, 3};

display(MainArray);
return 0;
}
name of the array is automaticly casted to (int*)
but what is the case I want to use two dimensional array ?
int main(void)
{
int MainArray[2][3] = {{1, 2, 3},
{4,5,6}};

display(MainArray);

return 0;
}

what should be the formal parameter of display function?
void display(int** Local Array) ? <-- Is it true?
That's a good question, which is why the answer is in the FAQ:
http://www.eskimo.com/~scs/C-faq/q6.18.html

Read the rest of it while you're there, it's good stuff.

S.
 
P

pete

Hi!
It is clear that when we try to pass a one dimentional array to a
function
we use int* such as

void display(int *LocalAarray)
{
......
}

int main(void)
{
int MainArray[3] = {1, 2, 3};

display(MainArray);
return 0;
}
name of the array is automaticly casted

"converted" is a more better word to use than "casted", there.
to (int*)
but what is the case I want to use two dimensional array ?
int main(void)
{
int MainArray[2][3] = {{1, 2, 3},
{4,5,6}};

display(MainArray);

return 0;
}

what should be the formal parameter of display function?
void display(int** Local Array) ? <-- Is it true?

void display(int (*Local_Array)[3]);
 
S

Skarmander

haroon said:
Skarmander wrote:
[snip]

That's a good question, which is why the answer is in the FAQ:
http://www.eskimo.com/~scs/C-faq/q6.18.html


who is responsible for this FAQ and what is the frequency of update?
Steve Summit ([email protected]) is the one responsible, and the last
update was on July 3, 2004 (this is the version posted monthly to the ng
and available through anonymous FTP at rtfm.mit.edu). Search Usenet
archives like Google's for the skinny.

S.
 
E

Eric Sosman

haroon said:
Skarmander wrote:
[snip]

That's a good question, which is why the answer is in the FAQ:
http://www.eskimo.com/~scs/C-faq/q6.18.html


who is responsible for this FAQ and what is the frequency of update?

Read the FAQ.

True, it only answers one of your questions completely.
But it gives a pretty good hint about the other, and I don't
think you deserve a more complete answer until you've given
some tiny indication that you're willing to expend two or
three of your own mouse clicks in pursuit of knowledge. You've
been served a URL on a silver platter; can you eat it yourself,
or do you need servants to lift each morsel to your lips, or
maybe even chew it for you?
 
K

Keith Thompson

Skarmander said:
haroon said:
Skarmander wrote:
[snip]
That's a good question, which is why the answer is in the FAQ:
http://www.eskimo.com/~scs/C-faq/q6.18.html
who is responsible for this FAQ and what is the frequency of update?
Steve Summit ([email protected]) is the one responsible, and the last
update was on July 3, 2004 (this is the version posted monthly to the
ng and available through anonymous FTP at rtfm.mit.edu). Search Usenet
archives like Google's for the skinny.

A more up-to-date version, in gzipped text format, is at
<ftp://ftp.eskimo.com/u/s/scs/C-faq/faq.gz>. The HTML pages don't
appear to have been updated since 1995.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top