FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
C++ PROGRAMMIN' r u any good?
Goto page Previous  1, 2, 3  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    The Ville.org Half-Life Gaming Community Forum Index -> General Ramblings
View previous topic :: View next topic  
Author Message
Twisted29
Registered User


Joined: 12 Aug 2001
Location: Rochester, NY
Posts: 1321

PostPosted: Mon May 06, 2002 5:40 pm    Post subject: Reply with quote

Lin, the asterik specifies a pointer. A pointer is a location in computer memory. It allows you not only to use then pointer value, but that data stored in that value. Actually, you can interept THAT data as a pointer and that THAT data as a pointer and you end up with nice things like stacks and trees. Good way to link data. Its also faster than passing values.

As far as programming a TI-83, they run off of a Motorola 68000 16-bit ASM. I have one too I've started making some cool stuff for it, maybe you can help me out with some of the linking interfaces? Any idea what ports are use for data transfer vs. handshaking?
Back to top
View user's profile Send private message Send e-mail AIM Address
Lin Sivvi Defiant Hero
Registered User


Joined: 17 Jan 2002
Location: Some small boring city
Posts: 1205

PostPosted: Mon May 06, 2002 5:46 pm    Post subject: Reply with quote

You lost me, right after the first few words Can you tell me a little more general idea of what it does to a variable compared to not having it with a variable?
Back to top
View user's profile Send private message Send e-mail AIM Address
CyC0Dad
Registered User


Joined: 19 Jul 2001
Location: Phoenix, AZ
Posts: 1382

PostPosted: Mon May 06, 2002 5:48 pm    Post subject: Reply with quote

The * says the variable is a pointer (contains the address of the value and not the value)

The & is used to define "The address of" so in this case I belive he is trying to define a variable that is of type pointer to store the address of "SomeVariable" to show how you can change the value of a variable via a pointer.
Back to top
View user's profile Send private message Send e-mail
Lin Sivvi Defiant Hero
Registered User


Joined: 17 Jan 2002
Location: Some small boring city
Posts: 1205

PostPosted: Mon May 06, 2002 5:51 pm    Post subject: Reply with quote

I now understand kind of. Thank you guys.
Back to top
View user's profile Send private message Send e-mail AIM Address
Warhammer
Server Admin
Server Admin


Joined: 12 Aug 2001
Location: Atlantuh, Jawjuh
Posts: 1226

PostPosted: Mon May 06, 2002 5:59 pm    Post subject: Reply with quote

In the simplest programming terms, here's what * and & are for (and other stuff like data types)..

All programs are simply sets of instructions executed in computer memory. Assume that the beginning of the program starts at "address 0" and goes up from there. When you declare a variable, via "int", "char", etc. you are setting up a chunk of memory for a particular purpose. If it's an "int" type (signed integer), it sets up (usually) 2 bytes. So if "int x" was the first thing you declared, it would be at address 0. If you then declared "int y", it would be at address 2. If you declared char name[10], it would start at address 4 and go through address 13, and so on.

Using & and * are ways to directly reference those addresses. It's a lot easier for functions to handle pointers to data structures than the structures themselves. Thus, you would use * to declare a type as being a pointer. So you could, in fact say:

char Name[20];
char *pName = &Name;

Then you would know that Name is the 20 char string, and pName is a pointer to that string. The & references the "address" of Name for use by the pointer.

Simple, right?

mwah ha ma wah hah whah... (a la Charlie Brown, for the non-programmers)
Back to top
View user's profile Send private message Send e-mail AIM Address
Twisted29
Registered User


Joined: 12 Aug 2001
Location: Rochester, NY
Posts: 1321

PostPosted: Mon May 06, 2002 6:00 pm    Post subject: Reply with quote

You still need a variable. I'll try to explain, but keep in mind its been a while since I've used C.

int var = 0;

That decalres a variable and initializes it to a value. The initialization (setting it to zero) is optional, but recommended. If you dont give it a value, you cant be sure of its starting value.

int *var1 = &var;

Now I'm just making a new variable, var1. I'm setting it equal to the memory location that var is stored in. You have to think of the computer memory as chunks of information. For this example, we'll call those chunks bits (even though bit, word, and long word allocations can be used in C). Say var is stored in bit #32 on your computer. Then var1 is equal to 32. This lets you do a couple things.

cout << var1;

Prints out 32

cout << *var;

Still prints out 32

cout << var;

Prints out 0

cout << *var1;

This will print out the location of var1 in memory. Which will be someplace completely different from var (unless you can initial memory location in C? I dont know).

What I mean about the stacks and such is this.

int var[5] = 0;
int *pointer = &var[0];

I made a five digit array (list of integers) and another value that points the first address in memory of the array. Say you want to know the 3 digit. You can just add 3 to pointer and then look at what data is stored in that location. It would give you the same result as var[3];.

The whole pointer concept is probably one of the most difficult things in C++ programming (excluding OOP if you get into that). So dont worry if you dont get it. I think everything you can do with pointers, you can also do with integers. But it takes more memory and more variables. Not sucha a big problem for the kinds of code you'll be working on in school. Once you get into large scale programming or ASM stuff, then you'll need to wory about pointers. Hope this helped

/* Please excuse any errors, like I said...its been a while for me */
Back to top
View user's profile Send private message Send e-mail AIM Address
CyC0Dad
Registered User


Joined: 19 Jul 2001
Location: Phoenix, AZ
Posts: 1382

PostPosted: Mon May 06, 2002 6:18 pm    Post subject: Reply with quote

Warhammer -TPF- wrote:


char Name[20];
char *pName = &Name;

Then you would know that Name is the 20 char string, and pName is a pointer to that string. The & references the "address" of Name for use by the pointer.

Simple, right?

mwah ha ma wah hah whah... (a la Charlie Brown, for the non-programmers)


Except that some compilers wouldn't like your example since you did char type and therefore Name would already be defined as an address because it was assumed to be a "string". You would get the address of the address in some compilers doing that. The safest syntax would be:

char Name[20];
char *pName = &Name[0];
Back to top
View user's profile Send private message Send e-mail
[Wolfpack]Deqlyn Moquei
Registered User


Joined: 22 Sep 2001

Posts: 73

PostPosted: Mon May 06, 2002 6:18 pm    Post subject: Reply with quote

Im not sure how close C++ is to VB6.0 but I think if int pvar is always going to be 5 then it needs to be Const con, but thats just VB6.0
Back to top
View user's profile Send private message
LanceMantis
Registered User


Joined: 12 Aug 2001
Location: Nebraska
Posts: 164

PostPosted: Mon May 06, 2002 6:18 pm    Post subject: Reply with quote

Well according to my friend in the comp sci dept. you cannot assign the value of the pointer like that. You make it point to memory address 9.
You have to de-reference it as a value. *pVar=9:
_________________
Shinu Kikai O Motomo

Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Warhammer
Server Admin
Server Admin


Joined: 12 Aug 2001
Location: Atlantuh, Jawjuh
Posts: 1226

PostPosted: Mon May 06, 2002 6:37 pm    Post subject: Reply with quote

CyCoDad wrote:

Except that some compilers wouldn't like your example since you did char type and therefore Name would already be defined as an address because it was assumed to be a "string". You would get the address of the address in some compilers doing that. The safest syntax would be:

char Name[20];
char *pName = &Name[0];


You're right, it's been a while since I've done programming with pointer manipulation. You could define char *pName and then say
pName = &Name though. Once you use the *pName then it turns back into a string since that dereferences the pointer.

[shuts his hole and goes back to Perl]
Back to top
View user's profile Send private message Send e-mail AIM Address
Lin Sivvi Defiant Hero
Registered User


Joined: 17 Jan 2002
Location: Some small boring city
Posts: 1205

PostPosted: Mon May 06, 2002 6:49 pm    Post subject: Reply with quote

I understand what you are saying, but I'm still feel stupid I'm too young to be thinking this hard
Back to top
View user's profile Send private message Send e-mail AIM Address
BitterBeerFace
Registered User


Joined: 17 Jan 2002
Location: Mankato, MinneSNOWta
Posts: 1416

PostPosted: Mon May 06, 2002 6:49 pm    Post subject: Reply with quote

LOL, yeah, I never learned enough C++ to learn pointers, which means i know nothing about it at all
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
Kilaak Kommander
Registered User


Joined: 21 Dec 2001
Location: Planut Kilaak
Posts: 135

PostPosted: Mon May 06, 2002 6:53 pm    Post subject: Reply with quote

KILAAK KOMMANDER LIKE GURLS WITH BIG THINGIES.
Back to top
View user's profile Send private message
Twisted29
Registered User


Joined: 12 Aug 2001
Location: Rochester, NY
Posts: 1321

PostPosted: Mon May 06, 2002 6:55 pm    Post subject: Reply with quote

BBF< how did you manage THAT kill? Looks like a good story....
Back to top
View user's profile Send private message Send e-mail AIM Address
Lin Sivvi Defiant Hero
Registered User


Joined: 17 Jan 2002
Location: Some small boring city
Posts: 1205

PostPosted: Mon May 06, 2002 6:57 pm    Post subject: Reply with quote

Hold a medpack out and take mirror from a grenade.
Back to top
View user's profile Send private message Send e-mail AIM Address
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    The Ville.org Half-Life Gaming Community Forum Index -> General Ramblings All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group