Changing char array value using pointers?

I'm trying to understand pointers. Can someone please explain why this doesn't work. However, if you change all of the types to type int, and the Z to an integer number, the program works fine. Basically, why can you not change the value of a char array?

**I noticed shortly after I posted that I was using "Z" instead of 'Z'**

#include <iostream>
#include <string>

using namespace std;

int main ()
{

char myarray [5];
char *p;

p = myarray;
*p = "Z";

cout<<myarray[0]<<endl;

system("pause");
return 0;
}
Last edited on
Topic archived. No new replies allowed.