"jagguy" <jo**********@o ptusnet.com.au> wrote in message
news:44******** *************** @news.optusnet. com.au...
if it is a constant then this shouldn't work but it odes
char *p ;
p="xbbat";
cout << p <<endl;
p="xbbat";
cout << p <<endl;
char *p; // <- this is just a pointer. it points to a location in memory
"xbbat" is a string literal, located inside the binary (.exe).
When you run your program it's loaded into memory.
you assignments will only set the value of the pointer p to point at the
area in memory that contains the string "xbbat" (wich is loaded into memory
with the program when executed).
char *p;
p = "string";
You do not assign the value "string" to p.
You do only set the value of p to the address in memory where the first char
of "string" is located.
However, you should not do what your doing.
It would make more sense to write:
const char *p = "sometext";
std::cout << p << std::endl;
witch is basicly the same as what you do.
//eric