![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 | |||
|
Programmer
Join Date: Dec 2005
Posts: 65
Rep Power: 3
![]() |
Quote:
A good practice problem is to make a function that takes a string and parses it into an array of tokens. For example: Quote:
Quote:
I feel this problem is fairly good at teaching you practical uses for pointers, and a string parser is something you may see in the field. |
|||
|
|
|
|
|
#12 |
|
Professional Programmer
Join Date: May 2005
Location: Woo - Boot Sector!
Posts: 294
Rep Power: 4
![]() |
DaWei: unfortunately i don't recall ever using a malloc, with or without a pointer, so there you go
![]() para: i'll have a look at what you mean, thanks...
__________________
www.heldtogether.co.uk |
|
|
|
|
|
#13 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
|
#14 |
|
Professional Programmer
Join Date: May 2005
Location: Woo - Boot Sector!
Posts: 294
Rep Power: 4
![]() |
i am not denying the fact that i do not know as much as you, and i do realise that it is a negative comment on my skill but i am currently researching as to what a malloc is!!
EDIT: I now know what it is, but i do not believe that i have had cause to use it yet...
__________________
www.heldtogether.co.uk |
|
|
|
|
|
#15 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
You'd probably be better of sticking to new than malloc anyway.
It is true you are investigating, which is positive.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#16 |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,038
Rep Power: 5
![]() |
Pointers are one of those concepts that can sometimes take a while to wrap your mind around. However, as others have said, knowledge of how to use them is essential in writing anything but the most trivial programs in an efficient manner. The only downside to pointers is that they have a huge potential to cause damage if they are misused, though in a secure operating system, errant pointers should no longer bring down the entire system, format your hard drive, or do other such catastrophic things as they could do under legacy operating systems like DOS.
This perceived potential for misuse coupled with the fact that learning to use them properly often takes a bit of practice are key reasons that certain languages discourage their use (C# comes to mind) or remove them entirely (Java). However, even this is an illusion. When you pass an object to a function in many of these languages, it does not pass the object itself, but a reference (read: 'pointer') to the object instead. This is because the language designers acknowledge the efficiency in doing so. However, using them in other ways is often clumsy at best. The support in C++ of low-level constructs such as pointers is a big reason that it's such a widely-used language. I suggest you follow the link in DaWei's sig to the pointers introduction. You might need to read it more than once as you play around with pointers. Don't trust the one on (I think) cprogramming.com; if it's the one I remember, it's full of subtle errors and misinformation. When you're done, you should be able to write a function to swap two variables, and actually have them be swapped. You should hopefully understand the relationship between a pointer and an array (the two can often be used synonymously), as well as the differences. You should learn how pointer arithmetic is performed, and that it is scaled according to the size of the pointed-at quantity (this is why pointers need a type, such as 'int' or 'char'). You should know why array[7] and 7[array] mean the same thing (hint: remember that addition is commutative).
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
#17 |
|
Professional Programmer
Join Date: May 2005
Location: Woo - Boot Sector!
Posts: 294
Rep Power: 4
![]() |
Thanks guys, i'm definately getting there now, i'm starting to understand, and i will read DaWei's intro...
Cheers! ![]()
__________________
www.heldtogether.co.uk |
|
|
|
|
|
#18 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
|
#19 |
|
Professional Programmer
Join Date: May 2005
Location: Woo - Boot Sector!
Posts: 294
Rep Power: 4
![]() |
OK i'll check out Narue's too...
EDIT: can't find it on Narue's site. Can i have a link?
__________________
www.heldtogether.co.uk |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|