Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 11th, 2004, 5:46 PM   #1
dnathe4th
Programmer
 
Join Date: Oct 2004
Posts: 32
Rep Power: 0 dnathe4th is on a distinguished road
a pointer refers to the location of memory which stores the value of a variable

that much I've gathered from online tutorials, but tell me this, why use pointers instead of the variables themselves?
__________________
&lt;CENTER&gt;<span style='font-size:17pt;line-height:100%'>My Homepage</span>&lt;/CENTER&gt;
dnathe4th is offline   Reply With Quote
Old Oct 11th, 2004, 6:44 PM   #2
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
Quote:
Speed: Imagine you want to write a progam that moves a lot of information around. In the conventional way, this would mean copying a lot of bytes from one part of the memory to another part. Take for example the sorting of an array with name.
(a pointer is just 4 bytes in Intel computers).

Flexibility: If, at the beginning of the program we do not know yet how many variables we need we would have to reserve space for all possible eventualities. If we want to write a program that calculates the first N prime numbers, with N given by the user, we would have to declare an array of maximum size to be sure that we can fit the users request in it. With this we would completely occupy the memory of the computer. Nothing else can run anymore. Much nicer would be if we could declare the array (the variables) dynamically so that we only use memory if we really need it. With pointers this is easily possible.

The pointers and the idea of dynamic creation of variables also lies at the basis of object-oriented programming, which is the type of programming of every modern computer language. Object oriented programming is outside the scope of this lecture, though.
http://w3.ualg.pt/~pjotr/pi/t14.html
__________________
&quot;Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Oct 11th, 2004, 11:32 PM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,473
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Speed. But its not so much that speed is an issue anymore as modern computers are excessively fast.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Oct 12th, 2004, 2:00 AM   #4
Ravilj
Programmer
 
Ravilj's Avatar
 
Join Date: Sep 2004
Location: JHB , South Africa
Posts: 79
Rep Power: 5 Ravilj is on a distinguished road
wait until you enter the world of object oriented programming and polymorphism, base classes, inheritance, virtual functions and base class pointers. Thats when pointers will show their uses.
__________________
Ravilj's OpenGL Terrain aka WinTerrain Last Updated: 17/01/2005!
Ravilj is offline   Reply With Quote
Old Oct 12th, 2004, 3:18 AM   #5
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
Pointers, linked Lists a must to learn but a headache all the same.
__________________
"Put your hand on a hot stove for a minute, and it seems like an hour. Sit with a pretty girl for an hour, and it seems like a minute. THAT'S relativity."

- Albert Einstein
Berto is offline   Reply With Quote
Old Oct 12th, 2004, 7:36 PM   #6
mici
Programmer
 
Join Date: Oct 2004
Posts: 67
Rep Power: 5 mici is on a distinguished road
Quote:
Originally posted by dnathe4th@Oct 11 2004, 09:46 PM
a pointer refers to the location of memory which stores the value of a variable

that much I've gathered from online tutorials, but tell me this, why use pointers instead of the variables themselves?
It's as simple as this...
pointers let you direct functions to go somewhere instead of you bringing it to them... when it comes to simple variables it's all the same but when it comes to structs and similar....

imagine it like this:
is it easier to tell your woman where the kitchen is or to go and cook dinner...
__________________
coffee is my heroin.
mici is offline   Reply With Quote
Old Oct 14th, 2004, 9:01 PM   #7
dnathe4th
Programmer
 
Join Date: Oct 2004
Posts: 32
Rep Power: 0 dnathe4th is on a distinguished road
Thanks guys, and by guys i mean MJordan
it makes a lot more sense now
Cheers
__________________
&lt;CENTER&gt;<span style='font-size:17pt;line-height:100%'>My Homepage</span>&lt;/CENTER&gt;
dnathe4th is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:44 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC