Difference between char**a and char *a[]

N

no

I hope this has not been discussed before.

But what is the
Difference between char**a and char *a[]

TIA.
 
C

CBFalconer

what is the Difference between char**a and char *a[]

At declaration time:

char **a; /* is a pointer to a pointer to char */
char *a[N]; /* needs the value of N, and is an array of char*
i.e. an array of pointer to char
N is not needed if specifically initialized */

In function prototypes:

char **a; /* is a pointer to a pointer to char */
char *a[ ]; /* doesn't need N, and no different than char** */

The results from "sizeof a" will differ in the two places for the
array like declarations. This IMO is a reason for declaring the
function parameter as char * or char ** as the case may be,
emphasizing that its value is that of a single pointer to
something.
 
M

Micah Cowan

CBFalconer said:
what is the Difference between char**a and char *a[]

At declaration time:

char **a; /* is a pointer to a pointer to char */
char *a[N]; /* needs the value of N, and is an array of char*
i.e. an array of pointer to char
N is not needed if specifically initialized */

Technically, you don't need N if a is declared with internal or
external linkage; but you still need to declare it with N
*somewhere* (in the same translation unit of internal linkage; in
any translation unit otherwise), so it doesn't buy you all that much.

-Micah
 
E

Eric Sosman

I hope this has not been discussed before.

Rather than merely hoping, you could do a little bit
of research. A good place to start is the comp.lang.c
Frequently Asked Questions (FAQ) list at

http://www.eskimo.com/~scs/C-faq/top.html
But what is the
Difference between char**a and char *a[]

This is essentially Question 6.2 in the FAQ. Don't
you wish you'd checked before posting the same old
question for the umpty-leventh time?

(Although the FAQ should be the first place you look
before posting, it isn't encyclopedic: brevity has value,
and the FAQ is brief. If you can't find any discussion
of your topic in the FAQ, it's a good idea to take a look
at the archives of the newsgroup's traffic at Google, and
it's a good idea to "lurk" on a newsgroup for a few weeks
before leaping into the fray all unprepared.)
 
G

Guest

Hello Eric Sosman,
I hope this has not been discussed before.

Rather than merely hoping, you could do a little bit
of research. A good place to start is the comp.lang.c
Frequently Asked Questions (FAQ) list at

http://www.eskimo.com/~scs/C-faq/top.html
But what is the
Difference between char**a and char *a[]

This is essentially Question 6.2 in the FAQ. Don't
you wish you'd checked before posting the same old
question for the umpty-leventh time?

6.2: But I heard that char a[] was identical to char *a.

I don't think it's the same :)
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top