I don't use pointers and references....

I need some help and opinions

Page 1 of 1

4 Replies - 646 Views - Last Post: 12 June 2009 - 06:10 PM Rate Topic: ***** 1 Votes

#1 athlon32  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 116
  • View blog
  • Posts: 363
  • Joined: 20-August 08

I don't use pointers and references....

Posted 12 June 2009 - 05:14 PM

Hello Everyone,

I have a dilemma. I've been programming in C/C++ for about a year now, and while I'm comfortable with the syntax of pointers and references, I never use them. Should I???

Could someone explain why or why not they are so important, and maybe give a good tutorial on how to apply them to make code better?

Thanks
~ mike
Is This A Good Question/Topic? 0
  • +

Replies To: I don't use pointers and references....

#2 Kanvus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 42
  • View blog
  • Posts: 452
  • Joined: 19-February 09

Re: I don't use pointers and references....

Posted 12 June 2009 - 05:37 PM

& cuts down memory usage by half because without it, things get cloned while passing. if you pass an array of 500 strings, it would use the memory of 1000 from one function call.

* is a pocket for holding big important things that come and go during runtime. allows program to improvise memory without having so many unused slots or run out of spots when the user wants more than you provided in hardcode.
Was This Post Helpful? 1
  • +
  • -

#3 Dantheman  Icon User is offline

  • D.I.C Regular

Reputation: 34
  • View blog
  • Posts: 445
  • Joined: 27-May 09

Re: I don't use pointers and references....

Posted 12 June 2009 - 05:45 PM

Use pointers to references variables in another scope.
Use pointers to dynamically allocate memory.

Reference is like a safe pointer. It can't be null. Can't be reassigned to another variable. Easier to use. But it can't be used to allocate memory.

This post has been edited by Dantheman: 12 June 2009 - 05:48 PM

Was This Post Helpful? 0
  • +
  • -

#4 athlon32  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 116
  • View blog
  • Posts: 363
  • Joined: 20-August 08

Re: I don't use pointers and references....

Posted 12 June 2009 - 05:48 PM

View PostKanvus, on 12 Jun, 2009 - 04:37 PM, said:

& cuts down memory usage by half because without it, things get cloned while passing. if you pass an array of 500 strings, it would use the memory of 1000 from one function call.

* is a pocket for holding big important things that come and go during runtime. allows program to improvise memory without having so many unused slots or run out of spots when the user wants more than you provided in hardcode.


Thanks for the explanation :D

Do you have an links to good online tutorials on applying pointers and references?
Was This Post Helpful? 0
  • +
  • -

#5 Kanvus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 42
  • View blog
  • Posts: 452
  • Joined: 19-February 09

Re: I don't use pointers and references....

Posted 12 June 2009 - 06:10 PM

Learn CPP Passing by Reference

43 antirtfm - what * and & are
44 antirtfm - how to use in functions

Learn CPP - Dynamic allocation - for huge chunks of pointers


An example of "applying" large memory is in games where you have to import vertex positions from a text file into your C++ 3d game.

Single pointers are used to change "states" of things. Like one pointer always knows what key you're pushing by holding its hex or binary number as an unsigned integer. Good for key input events handling.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1