Advertisement

Just seen something I don't understand.

Started by August 02, 2002 08:46 AM
4 comments, last by SteveBe 22 years, 5 months ago
Thicko here!!!! I''ve just seen a small example on the net and I don''t understand what''s going on. char name [20] ; char * SurnameStart = name ; while ( *SurnameStart != '' '' ) { SurnameStart++ ; } SurnameStart++ ; printf ( SurnameStart ) ; Its just to extract a surname from a first name and surname string. Why isn''t the pointer assignment statement this: char * Surnamestart = &name I''m guessing its something to do with the fact that name is an array but am not sure why. Also in the final printf statement why isn''t there an output specifier or a dereferencing operator. I thought it should look like this: printf ("%s", *surnamestart); Please explain someone.
your''re right about the array.
the array is in fact a pointer... that''s why you
don''t need the ''&''
Redefining the problem... is not SOLVING the problem!
Advertisement
quote: Original post by SteveBe
I''m guessing its something to do with the fact that name is an array but am not sure why.

It''s a syntax thing. If you refer to an array by the unadorned name, then you get a pointer to the start of the array. An array is *not* a pointer!
quote: Original post by SabreMan
It''s a syntax thing. If you refer to an array by the unadorned name, then you get a pointer to the start of the array. An array is *not* a pointer!


Actually SabreMan...

the name of an Array IS a pointer to the first element of that array. At least every book I''ve ever read says so.

so if you have

char test[4] = "abc"; 


the variable ''test'' is a pointer to the first value, or ''a''

Of course, I''m still pretty new to all this, so I may be wrong...



~~~~~~~~~~~
Chris Vogel
~~~~~~~~~~~
WyrmSlayer RPG - In Early Development
Courtesy of SabreMan: Arrays are Not Pointers


[My site|SGI STL|Bjarne FAQ|C++ FAQ Lite|MSDN|Jargon]
Ripped off from various people
[size=2]
I''m confused by your english
quote: Just seen something I don''t understand.


Just seen something? huh?

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

This topic is closed to new replies.

Advertisement