Jump to content

Pointers :@

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
Phoenixz

Phoenixz

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 256 posts
I get what pointers do, I know how to use them (atleast in the code part), but I have no idea how to use them practically.

So, can anyone give me some examples, or reasons why i'd need to use them. Thankyou for anyone who replies. ^-^

I know like.. it points to the memory address of the variable (or class) that we point it too, and that it can be used to point to the value aswell (& and *).
Posted Image

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Most importantly, you can allocate memory on the fly without using a named variable. If you have a named variable that is a pointer to a struct that contains a pointer to itself, you can then create a chain of structs with an arbitrary number of structs in the chain, all through one named variable.

Linked lists and other fundamental data structures would be almost impossible without pointers.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Phoenixz

Phoenixz

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 256 posts
hmm, well, okay thankyou for the information ^-^
Posted Image

#4
DarkLordoftheMonkeys

DarkLordoftheMonkeys

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 255 posts
Pointers have one major advantage: they make things dynamic. If you link objects together with pointers, you can create dynamic data structures like trees and linked lists, which are vital for more complex tasks. Pointers are also used in memory management. The usefulness of pointers may be unclear at first, but there are several books on the topics. Search "algorithms and data structures niklaus wirth". Wirth wrote a book that explains dynamic data structures pretty well, and it's available online. You can skip over some of the math if you don't like reading that stuff.
Life's too short to be cool. Be a nerd.

#5
genux

genux

    Learning Programmer

  • Members
  • PipPipPip
  • 80 posts
pointers are just cool :).

they allow for quicker of passing information between function as well, since they will point to the memory location and that is far quicker than just making a copy of the function parameter, and since it is a pointer you can still do some actions on it as well..

there are a few good reasons for pointers..

int coffeePerDay = 10; // need to cut down!!!

Codingfriends