3
Contributors
3
Replies
24
Views
4 Years
Discussion Span
Last Post by Ancient Dragon
1

char* name is a pointer, while char name[] is illegal because it is attempting to create an array of 0 elements. Some compilers may support declaring arrays with 0 elements, but that is an extension of the standards. It's quite dangerous to use non-standard constructs because that makes the program itself non-standard and may not compile with other compilers. If you instructor or someone else wants to compile your program with another compiler it mahy fail.

Edited by Ancient Dragon

0

None, ecept that char nam[] is usually followed by a string to intitialise it:

char name[] = "George Bush";

Whereas

char *name;

just declares a pointer, to be pointed at something later.

Edited by mathematician

0

char name[] = "George Bush";

In the above case name is a variable that resides in writable memory and you can change it's contents later however you wish (assuming you stay within the bounds of the array).

char* name = "George Bush"

In this case name is just a pointer that refers to a string in read-only memory. The string can not be changed, but the pointer can be changed to refer to something else.

Edited by Ancient Dragon

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.