Two questions really,
What is the difference between declaring *char Name, and char Name, and what are the advantages and disadvantages of using either declaration?
Thanks.
Two questions really,
What is the difference between declaring *char Name, and char Name, and what are the advantages and disadvantages of using either declaration?
Thanks.
Be a leader and not a follower.
I suppose you meant :
char* Name and char Name
The one with the asterisk(*), is a pointer to a char, which can hold the address of another char variable.
The one without the asterisk(*), is a normal char variable which can hold characters.
To clarify, both char* and char variables hold data, the difference is that the data for the char* variable, must be the address of a normal char variable.
ok, so do these two declarations have exactly the same affect?
char *FirstName="Dene", char FirstName[]="Dene\0";
Be a leader and not a follower.
Same effect, but remember that the pointer can also point somewhere else.
Eg.
btw you don't need to put the \0 in the initial string declaration.Code:char* ptr; char Name[] = "TestName"; char Surname[] = "TestSurname"; ptr = Name; cout << ptr; ptr = Surname; cout << ptr;