pointers

Aug 16, 2010 at 6:26pm
hi every body.
i have one fundamental question
in this code :
const char* a[2] = {"ab","bc"};
"a" array is a array of pointers but why we get it "ab" and "bc" instead of address?

Aug 16, 2010 at 6:40pm
Because in the expression :
cout << a[0] operator<<() is overloaded explicitly for char*.
Aug 16, 2010 at 6:47pm
if it's overloaded for char* so why when we write :
1
2
3
4
char a[3] = "ab";
char b[3] = "cd";
const char* names[4] = {a,b};
cout << names[0]; 

answer is "ab" instead of address of a[0];
Last edited on Aug 16, 2010 at 6:50pm
Aug 17, 2010 at 11:12am
well your are confusing yourself with array of pointers.
names is array of pointers to char.

so names[0] type is const char *,once you gives this type of datatype to any ostream or printf,it will print the data pointed by that pointer,in this case it will print ab.
Topic archived. No new replies allowed.