pass a 2-dimension array to function

S

snnn

How to pass a 2-dimension array to a function ?
How to write the decleartion of the function?
e.g.
int a[10][10];

I want to pass a to a function "func".
I wrote

void func(int a[][]); //error.

void func(int** a); //wrong type...


and,if a is a 1-deimension array like
int a[10];
what the type of a£¿
a is a point to an int value but not "int*" ?

const int*£¿
int const*?
int*¡¡const?

sorry,who can help me?
thanks!
 
S

S.Tobias

snnn said:
How to pass a 2-dimension array to a function ?
How to write the decleartion of the function?
e.g.
int a[10][10];
I want to pass a to a function "func".
I wrote
void func(int a[][]); //error.
void func(int** a); //wrong type...

void func(int (*a)[10]);
void func(int a[][10]);

and,if a is a 1-deimension array like
int a[10];
what the type of a?
a is a point to an int value but not "int*" ?

int a[10];
/*
Identifier `a' is an "array of int". In expressions (except when
preceded by `&' or `sizeof') `a' decays to "pointer to int".
*/

void func(int a[10])
{
/* Identifier `a' is a "pointer to int". */
}
 

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,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top