Regarding char Pointer

Hi,

char *s="yamaha";
cout<<s<<endl;

int *p;
int i=10;
p=&i;

cout<<p<<endl;

1) For the 1st "cout" we will get "yamaha" as output. That is we are getting "content of the address" for cout<<s.

2) But for integer "cout<<p" we are getting the "address only".
Please clarify how we are getting content of the address for char type only but not for other types.

Thanks
Sweta

character pointer types are special, they can point to strings of the standard C kind -- characters 1-127 in the string, character 0 as the terminator. It assumes they are C strings and thus is able to know where they end.

Integer pointer types do NOT define strings of any type that C++ knows, they're just pointers to integers. It could be pointing to one integer or many.

To print the content of a pointer really isn't that difficult. You can do:

cout << (*p) << endl;
cout << p[0] << endl;

Hi,

u will give a *p in cout code , then only u will get the value.

int *p;
int i=10;
p=&i;

cout<<*p<<endl;

Regards..
Rengasamy.E