February 23rd, 2003, 03:17 AM
Join Date: Feb 2001
Time spent in forums: 18 h 20 m 28 sec
Reputation Power: 14
Try looking in the pointer section. You also may want to get another book to cross reference troublesome problems. I can recommend Ivor Horton's Beginning C++ 6.
The "*" denotes a pointer. You can't assign a string of characters to a variable declared like this:
const char whatever;
Both "a_character" and "whatever" being of type char will only hold one character(and you have to use single quotes in the assignment statement). In the case of "whatever", it's declared constant, so you can't try to change its value later. On the other hand, an array of type char can hold a string of characters:
char some_text="This is the way to do it.";
and a pointer to type char (char*) can also hold a string of characters:
char* pwords="You can do it this way too.";
With both cases you can output the string using only the name:
Normally, if you try to print out a pointer like in the last line of code, the output will be an address in memory because pointers store addresses. However, pointers to type char are an exception: cout handles them differently and outputs the whole string.(Note: an array name is actually a pointer too.)
Last edited by 7stud : February 23rd, 2003 at 06:03 AM.