Zelaron Gaming Forum  
Stats Arcade Portal Forum FAQ Community Calendar Today's Posts Search
Go Back   Zelaron Gaming Forum > The Zelaron Nexus > Science and Art > Tech Help

 
 
Thread Tools Display Modes

 
C++ pointer help
Reply
Posted 2006-02-05, 02:29 PM
I'm just starting C++ and i do have a for dummies book on the subject so at least im covered there, anyway, i read the book(not all the way though, but I got past those parts) and I don't understand the point of using pointers and much less how to use them. can anyone help me? i'd appreciate it a lot. thanks!
Old
Profile PM WWW Search
sciencekid is neither ape nor machine; has so far settled for the in-betweensciencekid is neither ape nor machine; has so far settled for the in-between
 
 
sciencekid
 



 
Reply
Posted 2006-02-06, 12:09 PM in reply to sciencekid's post "C++ pointer help"
from my experience, do any of the excercises they tell you to do with pointers, its one of those things you really learn by using it. like i learned the point of them from when i use to make cheats for CS... but yea
Old
Profile PM WWW Search
Acer enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHzAcer enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHz
 
 
Acer
 



 
Reply
Posted 2006-02-06, 03:43 PM in reply to Acer's post starting "from my experience, do any of the..."
Check this out: http://www.daweidesigns.com/pointers.php

And as Acer said, you will use pointers for many different reasons. For now, just learn how they work, you will soon see their usefulness. They are essential in making certain data structures, as well as many other things.
Old
Profile PM WWW Search
Demosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to be
 
Demosthenes
 



 
Reply
Posted 2006-02-06, 11:09 PM in reply to Demosthenes's post starting "Check this out:..."
ok, what about this peice of code, what is it saying(from the "for dummies" book):

--------------------------------
#include <stdio.h>
#include <iostream.h>

class Student
{
public:
int semesterHours;
float gpa;
float addCourse(int hours, float grade){return 0.0;};
};

int main(int argc, char* pArgs[])
{
// create a Student object
Student s;

// now create a pointer to a Student object
Student* pS;

// make the Student pointer point to our Student object
pS =& s;

return 0;
}
------------------------
even w/ the comments, i still don't get what each pointer symbol means/does
Old
Profile PM WWW Search
sciencekid is neither ape nor machine; has so far settled for the in-betweensciencekid is neither ape nor machine; has so far settled for the in-between
 
 
sciencekid
 



 
Reply
Posted 2006-02-07, 06:52 AM in reply to sciencekid's post starting "ok, what about this peice of code, what..."
pS is a pointer that, as its value, has the address of s.

In that context, it's pretty useless. What you're going to be using it for in the beginning is passing it to functions. Since, if you pass a variable, you can only change it in the main function if you actually return it, pointers will become useful when you want to change more than one variable in a function.

If you pass the pointer, you can change the value of the pointer (which you'd never really want to do in this situation), and, more importantly, you can change the value of the variable that the pointer points to.

Really, just work these basic examples, and it'll become evident soon enough.
D3V said:
This message is hidden because D3V is on your ignore list.
What is it they say about silence being golden?
Old
Profile PM WWW Search
Medieval Bob enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHzMedieval Bob enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHz
 
 
Medieval Bob
 



 
Reply
Posted 2006-02-07, 11:17 AM in reply to Medieval Bob's post starting "pS is a pointer that, as its value, has..."
all right then, i'll try to practice it. but one more question..... mjordan2nd's link says that the pointer point to an address in the memory, right? but you say that it has to do w/ the variable's value, right? so which one is right? they can't both be correct, right? so which one is it? and sorry for being a pain in the rear w/ all this confusion i have. i just don't catch things so easily sometimes thanks for your help guys.
Old
Profile PM WWW Search
sciencekid is neither ape nor machine; has so far settled for the in-betweensciencekid is neither ape nor machine; has so far settled for the in-between
 
 
sciencekid
 



 
Reply
Posted 2006-02-07, 04:56 PM in reply to sciencekid's post starting "all right then, i'll try to practice..."
They are both correct. A pointer holds an address in memory. If you outputted the value of a pointer, you would get a memory address, which pretty much would look like random garble. However, you can use a pointer to change the value of a variable as well. By using the correct command, you basically say change the value of the address a pointer is pointing to. For instance, lets say pointer i points to variable x, and variable x's location in memory is 1234:5678. Lets say x is initially 10. If you wanted to change x's value to 20, you could do so using the pointer like so:

Code:
 *i = 20;
What that code does is it says, go to the address that i is holding, which also happens to be variable x's location, and change the value that address i is holding to 20, which therefore also changes x's value.
Old
Profile PM WWW Search
Demosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to be
 
Demosthenes
 
 

Bookmarks

« Previous Thread | Next Thread »

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

Posting Rules [Forum 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


All times are GMT -6. The time now is 02:26 AM.
'Synthesis 2' vBulletin 3.x styles and 'x79' derivative
by WetWired the Unbound and Chruser
Copyright ©2002-2008 zelaron.com
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.