not really...........
if you write this by itself:
compiler will flag an error b/c when you declare an array like this (on the stack) you ought to give it it's capacity...
and whether you declrare an array statically (as above) or dynamically, once you set its size you can't really change it...
to be o.k. on the terminallogy, by writing the following:
Code:
char str[] = "hello";
you have declared an array of 6 characters, b/c by enclosing the word (hello) in double quotes (" "), implicitly you include the terminating character (\0) which signifies the end of the C-style string...
and now when you write:
you must understand that the the name of your array (str) IS THE POINTER TO THE FIRST CHARACTER IN YOUR ARRAY, so in reality you are assigning (ptr) to be pointing to the same address as (str) is, which of course in this case is the first character in the array ( first character also being accessed by: str[0] )
keep in mind that if your character array wouldn't be initialized in double quotes, meaning it would not carry the terminating character at the end (\0) then you only would see the FIRST character on the screen, not the entire string...
for example:
Code:
char str[] = { 'h', 'e', 'l', 'l', 'o'};
char *ptr = str;
cout << ptr << endl; // prints to screen only letter h...
hope that makes things a lot clearer...
keep up the good work...
................
matheo917