A character pointer is a pointer to a character. A string is a sequence of
characters. Because of that, it is possible for a character pointer to
point at the first character of the string.
See more below.
/Per W
On Thu, 27 May 2004, Noorez Kassam wrote:
> Need some help understanding pointers.
>
> I can understand this
>
> int main()
> {
> char charArray[10];
> char* pArray = charArray;
> for(int i =0; i <10; i++)
> {
> *pArray ='\0';
> pArray++;
> }
> }
>
> I don't inderstand this. It came from a book I am reading
>
> char* pszMonth;
> pszMonth = "January";
Will point to the 'J' character of January. A printout using pszMonth will
then print out all characters until the terminating zero that ends the
string "January". The psz prefix means Pointer to Zero-terminated String.
The assign is of course without a '*' since the assign is of one pointer
(address of string "January" to another pointer pszMonth. Had a star been
used on pszMonth, you might have written:
char ch;
char* pszChar = &ch; // Make pointer point at some available space.
*pszChar = 'J'; // Assign a character to *pszChar position, i.e. ch.
ch will now be 'J', since pszChar pointed to ch - thereby making the above
assignment the same as ch = 'J'.
>
> this is just a bit of code. But I don't see how this can be. First how can
> you make the assignment without the * and how can you put a string in a char
> pointer. A char like that should only hold one character.
>
> _________________________________________________________________
> Add photos to your e-mail with MSN Premium. Get 2 months FREE*
> http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: Oracle 10g
> Get certified on the hottest thing ever to hit the market... Oracle 10g.
> Take an Oracle 10g class now, and we'll give you the exam FREE.
> http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|