By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,299 Members | 1,409 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,299 IT Pros & Developers. It's quick & easy.

pointers for beginners

P: n/a
I've put off posting this for a few days but this is still giving me
grief:
I just starting learning standard C and I plan to learn properly.

I *think* I understand pointers, however after writing some code that
used an array of pointers, I found that I could quite easily achieve
the same result with normal arrays.

This suggests to me that I am missing something here.

Could someone suggest an exercise where using pointers would be
essential?

Nice one very much in advance, Matt

Dec 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
ballpointpenthief wrote:
I've put off posting this for a few days but this is still giving me
grief:
I just starting learning standard C and I plan to learn properly.

I *think* I understand pointers, however after writing some code that
used an array of pointers, I found that I could quite easily achieve
the same result with normal arrays.

This suggests to me that I am missing something here.
I would suggest reading sections 4, 5, and 6 of the comp.lang.c FAQ
available at http://www.eskimo.com/~scs/C-faq/top.html (You would
undoubtedly benefit from reading the entire FAQ but the sections I
listed are a good start for your situation)
Could someone suggest an exercise where using pointers would be
essential?


Storing the return value of malloc (or one of many other standard
functions that return a pointer). Unlike many other languages,
pointers play an integral role in C and a full understanding of how
they work is essential to realizing the potential of the language.

Robert Gamble

Dec 19 '05 #2

P: n/a
"ballpointpenthief" writes:
Could someone suggest an exercise where using pointers would be
essential?


Write code for a linked list. You can find tutorial on the Web as to the
essentials you need to know.
Dec 20 '05 #3

P: n/a
On 19 Dec 2005 14:34:42 -0800, "ballpointpenthief"
<Ma*************@gmail.com> wrote:
I've put off posting this for a few days but this is still giving me
grief:
I just starting learning standard C and I plan to learn properly.

I *think* I understand pointers, however after writing some code that
used an array of pointers, I found that I could quite easily achieve
the same result with normal arrays.

This suggests to me that I am missing something here.

Could someone suggest an exercise where using pointers would be
essential?


How would you handle dynamic memory allocation if the returned value
was not a pointer?

How would strtok tell you where the next token started if it did not
return a pointer?

Whenever an array is passed to a function, the actual value passed is
a pointer to the first element of the array.

When a function must return multiple values (e.g., strtol), the
address of the variables to receive these values are passed as
arguments and treated as pointers by the receiving function.
<<Remove the del for email>>
Dec 20 '05 #4

P: n/a

ballpointpenthief wrote:
I've put off posting this for a few days but this is still giving me
grief:
I just starting learning standard C and I plan to learn properly.

I *think* I understand pointers, however after writing some code that
used an array of pointers, I found that I could quite easily achieve
the same result with normal arrays.

This suggests to me that I am missing something here.

Could someone suggest an exercise where using pointers would be
essential?

/* a function to swap two variables */
void swap (int* a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}

int main (void)
{
int x = 1;
int y = 2;
swap (&x, &y);
return 0;
}
--
Nick Keighley

Dec 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.