char *c,char c[ ] and char *c[ ] 
Author Message
 char *c,char c[ ] and char *c[ ]

Dear Sir/Madam,

        My Question is "what is the difference between char *c,char c[]
  and char *c[] ?.Also when does char *c and char c[] are considered equal ?".

Thanks in advance,
Sekhar H.



Tue, 03 Feb 2004 22:23:08 GMT  
 char *c,char c[ ] and char *c[ ]

Quote:

>         My Question is "what is the difference between char *c,char c[]
>   and char *c[] ?.Also when does char *c and char c[] are considered equal ?".

That is phrased suspiciously like a homework question. However:

char *c is a pointer to char.
char c[] is an array of chars.
char *c[] is an array of pointers to char.

char *c and char c[] are considered equal in function declarations,
_and_ under some other circumstances by people who are considerably
muddled about pointers and arrays.

Richard



Tue, 03 Feb 2004 22:52:59 GMT  
 char *c,char c[ ] and char *c[ ]

Quote:
> Dear Sir/Madam,

>         My Question is "what is the difference between char *c,char c[]
>   and char *c[] ?.

The difference is, the first is read "c is a pointer to char",
the second "c is an array of char but with unspecified size, so
it is of incomplete type" if in a definition, but "c is a
pointer to char" when in a function definition. The third
reads "c is an array of pointers to char", again this would
only be true if there was a size given to the array.
One can use the forms with [] in declaring function parameters,
because in a function parameter list an array decays to a pointer.

Quote:
>Also when does char *c and char c[] are considered equal ?".

Never.

--

"LISP  is worth learning for  the profound enlightenment  experience
you will have when you finally get it; that experience will make you
a better programmer for the rest of your days."   -- Eric S. Raymond



Tue, 03 Feb 2004 23:34:13 GMT  
 char *c,char c[ ] and char *c[ ]
Sekhar,
  *c is a character pointer,
   c is an character array,
  *c[] is a array of character pointer.
Quote:
>>.Also when does char *c and char c[] are considered equal ?".

*C is an pointer variable, which could hold any address value whereas
c[] is an array once declared can't be changed.Take a look at the
example below:-
int main(void)
{
char *c;
char a[];
c=a; /* this is correct */
c= (char *) malloc(sizeof(int)); /* this is also correct */
a=c; /* This is an error, you can't reinitilize array */
Quote:
}

I hope it will help.

-MT

Quote:

> Dear Sir/Madam,

>         My Question is "what is the difference between char *c,char c[]
>   and char *c[] ?.Also when does char *c and char c[] are considered equal ?".

> Thanks in advance,
> Sekhar H.



Wed, 04 Feb 2004 02:11:51 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Converting char array of literals chars to escape chars

2. char, unsigned char, signed char

3. A char pointer (char *) vs. char array question

4. Convert char* to char __gc[]

5. problem assigning char* to char*

6. char** and const char** ...

7. char* -> char (newbie question)

8. char *c vs. char c[]

9. what is the difference between this types: char and System.Char

10. Char to Wide-Char tool

11. NewBie: difference between char* and unsigned char*

12. Difference between char* and char[]

 

 
Powered by phpBB® Forum Software