Thread: Pointer exercises

  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688

    Pointer exercises

    Does anyone know of any good links to some exercises on Pointers? I have tried google and it always turns up dud pages for me. Ant help appriciated. I have done all the ones in my book and want to do more. I dont want to move on untill I feel I can handle them at a level I am comfortable with.
    Double Helix STL

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    What level are you at? Here are some introductory ones:
    1. make strcpy without an array, but with pointer arithmetic. make one for wide characters too.
    2. make a singly linked list
    3. make a double linked list
    Last edited by robwhit; 12-15-2007 at 08:41 AM. Reason: sp

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Look for C exercises.

    Or practice not using pointers in C++.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Daved View Post
    Look for C exercises.

    Or practice not using pointers in C++.
    Whilst avoiding pointers generally is a good thing, there are plenty of things that get very difficult if you DON'T have pointers. The typical instances include linked lists and trees. Of course, you can implement this by using some standard container class, but it gets a little bit clunky if you HAVE to do it that way every place you need a simple linked list to store things in a queue, stack or list, and the arranging is really simple.

    If you haven't done that yet, build a stack as a linked list. Then convert it to a queue.

    Once you have that working, you could practice your C++ skills by making it into a template classes, using the same interface as a std::stack, std::queue, std::list, including a basic iterator class.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    It gets clunky if you don't use standard containers when you need a simple linked list.

    But my point was that virtually all the tasks for working with pointers that would be helpful to learn can be found by doing C exercises. So if you look for C exercises you are more likely to find good pointer exercises.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Daved View Post
    But my point was that virtually all the tasks for working with pointers that would be helpful to learn can be found by doing C exercises. So if you look for C exercises you are more likely to find good pointer exercises.
    Yes, I agree with that.

    I guess I'm still very much thinking as a kernel programmer, even if much of the code I write right now is user-mode [but still part of the OS services, so it needs to be both efficient, and since it's used in an embedded environment, not too much memory]. Not helped much by the lack of a STL implementation in our world...

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick Pointer Question
    By gwarf420 in forum C Programming
    Replies: 15
    Last Post: 06-01-2008, 03:47 PM
  2. Replies: 1
    Last Post: 03-24-2008, 10:16 AM
  3. Parameter passing with pointer to pointer
    By notsure in forum C++ Programming
    Replies: 15
    Last Post: 08-12-2006, 07:12 AM
  4. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM