Difference between result of character and integer pointer
I was trying to execute the following code:
#include <iostream>
using namespace std;
int main ()
{
int arr[4]={1,2,3,4};
int *p;
p=arr;
cout<<"p="<<p<<endl;
char ch3[4] = {'c','d','e'};
char *ptr;
ptr = ch3;
cout<<ptr<<endl;
getchar();
return 0;
}
When I print the pointer p, it prints the address of the array 'arr' which
is stored in it, whereas when I print the pointer ptr, it prints the array
ch3 and not the address of it. I wanted to know why is this happening.
No comments:
Post a Comment