Never assign raw data directly to an uninitialised pointer. If done so, where would the pointer point to? Where will the raw data be stored? Maybe it will compile, maybe it won't. Maybe it could lead to disastrous effects. You have to make sure a pointer points to something (safe) before using it. So: char *st="myname"
is plain wrong.
Anyway, a pointer variable, declared with an asterisk operator, ie: char * a;
, is a variable that contains an address. This pointer still needs to be assigned, so let's say we assign st's (an array) address to it: a = st;
Printing a, then, will show the address of st's first element, wherever it is in memory. By using a dereference operator (asterisk), you can access the value in the address that the pointer points to, ie: cout << *a
shows st's first element.
An array is a block of memory reserved depending on the indicated size. By using the name in conjunction with an index, it's use is similar to a pointer in such that the value located in the array's first element address, offset by the index is being accessed. The main difference between the two is that arrays have fixed addresses, whereas pointers can be reassigned different addresses.
Examples:
char st[] = "myname";
char * a = st; // valid, because pointers can be assigned new addresses as values
st = a; //invalid, because array addresses are fixed
cout << *a; // outputs st[0]
a = &st[1]; // assigns …