|
char *c,char c[ ] and char *c[ ]
Author |
Message |
Sekhar Ha #1 / 5
|
 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 |
|
 |
Richard B #2 / 5
|
 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 |
|
 |
Zoran Cutur #3 / 5
|
 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 |
|
 |
Mahesh Tom #4 / 5
|
 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 |
|
|
|