Go to Post I always love the optimism of [build] week 1. - Donut [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 21-03-2012, 10:36
DjScribbles DjScribbles is offline
Programming Mentor
AKA: Joe S
FRC #2474 (Team Excel)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Niles MI
Posts: 284
DjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to behold
Re: C++ help: Understanding pointers?

Pointers are exactly what they sound like, if you have encountered 'References' a pointer is very similar. A pointer is literally the memory address of a piece of data, the type you assign to the pointer dictates what you expect to find at that address (such as a class, an array, or an integer).

You use a pointer typically to avoid moving around big chunks of memory. If you imagine the basic robot class, it has a large number of variables for motors drive systems etc, all of these are stored in memory. If you call a funtion and pass in the ACTUAL robot, you end up making a copy of the whole robot (remember if you change a variable you pass into a function, you are changing a copy, not the original) which can be a lot of memory to copy and is quite wasteful. If you simply pass a pointer, you essentially say "our robot is located a memory address 0x800f000" and that pointer (the address only) becomes the variable which is copied into memory, when you look up that memory address you get the real robot, so if you change attributes of the robot, you are not changing a copy, but rather the real robot.

A semi-similar example would be if you were trying to send someone a file you downloaded from the internet, you could either email the file itself (giving them a copy of the same file) or email them a link to the file. In both cases they have access to the file, but the latter is more efficient.
  #2   Spotlight this post!  
Unread 21-03-2012, 10:54
efoote868 efoote868 is offline
foote stepped in
AKA: E. Foote
FRC #0868
Team Role: Mentor
 
Join Date: Mar 2006
Rookie Year: 2005
Location: Noblesville, IN
Posts: 1,425
efoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond repute
Re: C++ help: Understanding pointers?

Usually "a pointer to a pointer" is used with 2d arrays. The first pointer points to an array of pointers, which each point to their own arrays.

The first time I encountered a pointer to a pointer, I was writing a function that set the address of a block of memory I allocated to the address that was passed in.

Can get pretty complicated, usually it's easier to draw a picture.
__________________

Be Healthy. Never Stop Learning. Say It Like It Is. Own It. Like our values? Flexware Innovation is hiring!. We're looking for Senior Automation, Software, and System Engineers. Check us out!
  #3   Spotlight this post!  
Unread 21-03-2012, 11:06
Bongle's Avatar
Bongle Bongle is offline
Registered User
FRC #2702 (REBotics)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Waterloo
Posts: 1,069
Bongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond repute
Send a message via MSN to Bongle
Re: C++ help: Understanding pointers?

The way I try to teach pointers to our kids is to analogize them to book pages.

If I have a book of 100 blank pages, then a pointer is like me saying "hey george, write something on page 5". That "page 5" is telling george the address that I want him to write to.

A pointer to a pointer would be: "hey george, go to the page number you find on page 5". Whenever you say "page __", that's a pointer. A pointer to a pointer to a pointer would be "hey george, go to the page number you find on the page you found on page 5".

The main problem with this analogy is that 'page' is a term for a related memory concept, but you don't need to learn about that until much much later.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 01:39.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi