making it practical

This is a discussion on making it practical within the C++ Programming forums, part of the General Programming Boards category; heya all this may seem weird but i understand pointer arithmetic etc but i cannot see the practical use(sounds dumb ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    10

    making it practical

    heya all
    this may seem weird but i understand pointer arithmetic etc but i cannot see the practical use(sounds dumb huh)
    i'll be cool if someone could probably give me a nice lil example on it so i could be enhanced mentally as a c++ programmer
    thanks

    zbap

  2. #2
    Unregistered
    Guest
    for most things you can get by without pointer math. The most straightforward place to use it is with arrays but the compiler has already been developed such that you don't have to do it. Basically:

    int array[10];

    cout << array[5]; means display the sixth element of the array;
    you could get the same thing by doing this:

    int *ptr = array;
    cout << *(ptr + 5);

    but why bother. If you like doing pointer math, so be it. But most of us prefe to use the work arounds already built into the compiler

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    For most programming projects you won't use pointer arithmetic that exceeds the increment operator. There are times where you will find that pointer arithmetic will solve the problem where other notations failed because with something like array notation the compiler must interperet your intentions where with pointer notation you give explicit directions. I've cleared several errors from my code simply by switching from array notation to pointer notation.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making sprites
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 02-20-2010, 06:00 AM
  2. Making great graphics
    By MadCow257 in forum Game Programming
    Replies: 1
    Last Post: 02-20-2006, 10:59 PM
  3. Making control...
    By Finchie_88 in forum C++ Programming
    Replies: 2
    Last Post: 09-07-2004, 01:42 PM
  4. Replies: 2
    Last Post: 01-13-2003, 12:28 PM
  5. About Unix Programming - Making a career desision
    By null in forum C Programming
    Replies: 0
    Last Post: 10-14-2001, 07:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21