Re: understanding pointers
Quote:
It should actually print address of y array!
It prints correctly. p is a pointer to a char which has been set to the address pointed to by y. cout sees that the type of p is of char * (pointer to char) and so treats it as a c null-terminated string and prints its contents.
Re: understanding pointers
@PM2kaud- Thank you for your reply.
So basically with string, the base address is passed and prints until it finds '\0'
Please correct me, if I am wrong.
Quote:
Originally Posted by
2kaud
It prints correctly. p is a pointer to a char which has been set to the address pointed to by y. cout sees that the type of p is of char * (pointer to char) and so treats it as a c null-terminated string and prints its contents.
Re: understanding pointers
Yes - for a c-style null terminated string. In c++ there is also a class called string which is very different.
Re: understanding pointers
Ohh.
Thank you once again.
Quote:
Originally Posted by
2kaud
Yes - for a c-style null terminated string. In c++ there is also a class called string which is very different.