Pointers

What is the difference b/w
1)char **n
and
2) char n[][]
Or is it the same?
Pls justify with answer
Question asked in interview
[170 byte] By [Alpha Vijayan] at [2007-11-18 19:16:12]
# 1 Re: Pointers
char** ppc is a pointer with allocated memory for the pointer itself,
it can get other address to point to, and its pointer arithmetic is
calculated with units of sizeof(char*)

char pcArr[][COL] is a constant addressed array, the memory is allocated (in a continuous row)
for the elements, and its pointer arithmetic is
calculated with units of sizeof(char)*COL
Guysl at 2007-11-9 0:32:19 >
# 2 Re: Pointers
Thanku for the reply.
BUt the answer i got the interviewer is that the two are same.Do u agree?But I consider it as different.
On what way char **n,char n[][] same?I amnot getting??
Alpha Vijayan at 2007-11-9 0:33:22 >
# 3 Re: Pointers
Originally posted by Alpha Vijayan
What is the difference b/w
1)char **n
and
2) char n[][]
Or is it the same?
Pls justify with answer
Question asked in interview First, there is no such declaration as char n[][].

Second, if the correct declaration were made, a two dimensional array is not the same as a char **. If it were the case, then this would not produce an error:

void foo(char n[][10])
{
}

int main()
{
char **p;
char somearray[10][10];
p = somearray; // error
foo(p); // error
}

The interview is making the mistake of stating that a pointer is an array when you declare them. This is not true and never has been true. A pointer is a pointer, and an array is an array.

A lot of faulty and buggy code has been written assuming that T** is the same as a T[m][n], especially when passing a T[m][n] to a function that takes a T**.

Regards,

Paul McKenzie
Paul McKenzie at 2007-11-9 0:34:31 >