Er,
const char * s = "Hello";
This is fine, since
s is a pointer to the first character in the immutable character array
"Hello".
const char * x[] = "Hello";
It is an error, because the "[]" syntax means you are trying to create a mutable array of (const char*) with size given by the initializer.
However, your initializer is the element's element type.
const char * x[] = { "Hello" };
All better.
int * x = 5;
The only reason this won't compile is because assigning an address directly is probably not what you meant to do. If you really did mean to try and access memory location 5, use a cast:
int * x = (int*)5;
Again, this compiles, but it is the wrong thing --
x now is a pointer to an integer at address
5 in memory, and the OS will probably disagree with you about trying to access it.
If what you really want is a pointer to an integer, anywhere in memory that you are allowed to touch, and that integer has the value five, then:
1 2
|
int * x = new int;
*x = 5;
|
Don't forget to
delete x;
before your program terminates.
Hope this helps.