Array name

There are two arrays, for example:

int pt1[]={1,2,3};
char pt2[]={'R','u','s','s','i','a'};

As I understand pt1 is the memory address of pt1[0]. The same result is for other types as float, double.
However, the second one pt2 is just string "Russia". It is not a value of memory address.

Can you explain the reason to me, please. Thank you.
[ptr2] is not a value of memory address.

No, ptr2 is a memory address just as ptr1 is.

However, std::operator << overloads const char * to provide for outputting C-style strings.
http://www.cplusplus.com/reference/ostream/ostream/operator-free/

Note that your pt2[] does not have a null terminator therefore operator << would not know how long pt2 is and would continue to print garbage after the 'a'.


pt2 does not differ from pt1 except for the type. Everything that you can do with pt1 you can also do with pt2.
Topic archived. No new replies allowed.