* pointers
@ 2005-10-30 8:11 ework0
2005-10-31 13:07 ` pointers HIToC
0 siblings, 1 reply; 2+ messages in thread
From: ework0 @ 2005-10-30 8:11 UTC (permalink / raw)
To: linux-c-programming
Hello,
I would like to know what are the advantages of use pointers to
insert/modify values in an array of characters for example.
char myword[2];
*myword = 'h';
*(myword + 1)='i';
why would i use this ( the intruction: *(myword + offset))?
what is the advantages of use this manipulation of array with these
pointers ?
In the last line, do I increment the address that contains what s points
to right ??
Why I increment it in '1' instead of a memory word concept?
Thanks
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: pointers
2005-10-30 8:11 pointers ework0
@ 2005-10-31 13:07 ` HIToC
0 siblings, 0 replies; 2+ messages in thread
From: HIToC @ 2005-10-31 13:07 UTC (permalink / raw)
To: ework0; +Cc: Linux C programming
On Sunday 30 October 2005 09:11, ework0 wrote:
> I would like to know what are the advantages of use pointers to
> insert/modify values in an array of characters for example.
With a pointer you can have access to a single element of an
array in a very easy and fast way. Probably your example was
not the best for this purpose; considere this one:
char str[16] = "0123456789ABCDEF";
char* p = str;
Now p points to the first element of the array str. If you want
to obtain or to modify the element pointed by p, you can do
this by simply operating on p. Remember that the operations
like p++, will not modify the element pointed by p, but only
p will point the next element in the array.
> what is the advantages of use this manipulation of array with these
> pointers ?
When you have to scan big sequences of objects, is a very common
way to use pointers in order to have the access to a single element
or when you pass an object to a function passing the address and not
to copy the entire object.
A wrong use of pointers can cause errors difficult to find.
--
With regards,
HIToC
hitoc_mail@yahoo.it
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-10-31 13:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-30 8:11 pointers ework0
2005-10-31 13:07 ` pointers HIToC
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).