I know that name of Array is address of first element and so I expect it just to print address of first element. but it prints all of the elements in Array:
phone
I tried it with int data type and it just prints address of first element.
1 2 3
int num[10]={1,2,3,4,5};
int* ptrToNum=num;
cout<<ptrToNum<<endl;
Result:
0x22ff20
I am wondering if someone can tell me why they give me different answers. One of the pointers prints all of the elements and other one prints Address of first element.
This happens because the << operator of the cout object is designed to behave differently for different types. The mechanism used to do that is called (operator) overloading. I guess you'll eventually learn about that.
The default behavior of cout-ing a char pointer is printing the entire string because that's what you almost always want to do with a char pointer. Of course, there are ways to get the address: