|
From: <dan...@ya...> - 2004-05-28 14:19:41
|
--- Noorez Kassam <coo...@ho...>
escreveu: > I have asked questions about pointers and
arrays but
> int nArray[5]={1,2,3,4,5};
> cout << nArray << endl;/*this gives the address
> of the array*/
Yes, this is the default for pointers; if you use just
the name of the array, you get the address of the
begining of the array; so nArray acts just like a
pointer.
> char sArray[6]={'h','e','l','l','o',\0};
> cout << sArray << endl;/*this give the string
> hello, but i used the name
> of the array without subscripts? Don't i get the
> address of it like in the
> int array?*/
No. The << operator for ostream's is overloaded to
handle pointers to char (char*) in a special way. If
you cast your sArray (when you're printing it) to
another type, like void*, you'll get the address. i
suggest you to start first with C, not with C++. Or
get yourself a good book (D&D, TC++PL and so on).
> char* pszString = "hello";/*strangest of all*/
Isn't strange at all. You are declaring a C string
constant, and pointing pszString to it.
Daniel K. O.
______________________________________________________________________
Participe da pesquisa global sobre o Yahoo! Mail:
http://br.surveys.yahoo.com/global_mail_survey_br
|