Consider the below example
int nCount[2] = {5,10};
int* ptrInt;
ptrInt = nCount;
cout<<ptrInt<<Endl;//this will print the address of arrar nCount
now consider this
char *str = "Idle mind is a devil's workshop";
int nLen = strlen(str);
char* ptr;
ptr = new char[nLen+1];
strcpy(ptr,str);
cout<<ptr<<endl;//this wil print the string
but shouldnt this be printing the address of str. I am not quite getting the difference.
Since
char*s are frequently used for storing strings, the ostreamoperator<<is overloaded forchar*to print out the pointed-to string instead of the pointer.If you want to output the pointer, you can cast the pointer to
void*and then output that.