Honda and Acura Car Forums banner

Help in c

847 Views 20 Replies 4 Participants Last post by  MKX-R
This may sound weird but can someone please explain to me about pointers and the referencing and dereferencing thingy about the pointers. i understand a little about it, i just need someone to clarify it.
1 - 20 of 21 Posts
hmm, it's been a while, but here it goes. Pointer is practically a variable with a memory address in it which using that address POINTS towards 'whatever' is stored in that memory location, it could be an actual variable stored there, or another pointer (which leads to linked lists and so on).

this I am not 100% sure about, but referencing a pointer means that you pass on the value that it points to (the value stored in the memory location that the pointer points to). I'm not sure I can explain this any other way,
I won't try to crack the 'dereferencing' coz I'm not sure what it really refers too, ah, too many buzz worsds related to poitners. But once you understand them, you won't even look up these definitions anymore.
thanks, how about some of the syntax of using pointers, got any examples that may help me understand it a bit?
ouch, that will be a problem, I haven't programmed in C in few years, so I don't have any of my source files anymore.
to declare a pointer, it's as simple as:
int *ptr;
<variable type> *<name of variable>;


now pointers basically store memory addresses. so to point a pointer to a variable, you'll have to pass it the address of the variable. to get the variable's address, you use the ampersand (&) operator.

for example, create an integer called x:
int x;

now assign it a value of 4:
x = 4;

next declare a pointer variable of int type:
int *ptr;

now you can give ptr the memory address of x:
ptr = &x;

run the following program. you'll get an idea of the difference between the ampersand and no ampersand:
#include <iostream.h>

void main()
{
int x; // create an integer variable called 'x'
x = 10; // put value of '10' into variable 'x'

cout << "the value of 'x' is " << x << endl
<< "the memory address of 'x' is " << &x << endl;
}


last but not least, to pass the address of the variable, leave the asterisk in front of the pointer out:
WRONG: *ptr = &x;
RIGHT: ptr = &x;

so w/ that in mind, you tell me:
using the assignments from above the sample program (where x = 4), what does cout << *ptr; give me?
and what does cout << ptr; give me?

good luck.
See less See more
blitzkrg said:
to declare a pointer, it's as simple as:
int *ptr;
<variable type> *<name of variable>;


now pointers basically store memory addresses. so to point a pointer to a variable, you'll have to pass it the address of the variable. to get the variable's address, you use the ampersand (&) operator.

for example, create an integer called x:
int x;

now assign it a value of 4:
x = 4;

next declare a pointer variable of int type:
int *ptr;

now you can give ptr the memory address of x:
ptr = &x;

run the following program. you'll get an idea of the difference between the ampersand and no ampersand:
#include <iostream.h>

void main()
{
int x; // create an integer variable called 'x'
x = 10; // put value of '10' into variable 'x'

cout << "the value of 'x' is " << x << endl
<< "the memory address of 'x' is " << &x << endl;
}


last but not least, to pass the address of the variable, leave the asterisk in front of the pointer out:
WRONG: *ptr = &x;
RIGHT: ptr = &x;

so w/ that in mind, you tell me:
using the assignments from above the sample program (where x = 4), what does cout << *ptr; give me?
and what does cout << ptr; give me?

good luck.
hmmmm, let me take a stab at this:

cout << *ptr will output the value 10
and cout << ptr will output the address of x


....haven't done this in a while :confused:
RONIN-1 said:
hmmmm, let me take a stab at this:

cout << *ptr will output the value 10
and cout << ptr will output the address of x


....haven't done this in a while :confused:
excellent... someone's paying attention. :D
HAHA, it's a classroom in here :)
MKX-R said:
HAHA, it's a classroom in here :)
I wish I could get some help on this code I'm writing for a website I'm creating. It's in ASP

:confused: :mad:
RONIN-1 said:
I wish I could get some help on this code I'm writing for a website I'm creating. It's in ASP

:confused: :mad:
wrong classrom :) asp isn't my cup of tea, there are easier ways to get things done, hmm, like coldfusion :)
MKX-R said:
wrong classrom :) asp isn't my cup of tea, there are easier ways to get things done, hmm, like coldfusion :)
I'm so used to using ASP and i like it :D

but eventually I'll try and sharpen my coldfusion skills...

anyway, whatever... I got my code working anyway... the site looks decent enough...

Bah! :mad:
RONIN-1 said:
I'm so used to using ASP and i like it :D

but eventually I'll try and sharpen my coldfusion skills...

anyway, whatever... I got my code working anyway... the site looks decent enough...

Bah! :mad:
link us up, show off what you did :)
MKX-R said:
link us up, show off what you did :)

lol... it's far from complete but here....

(keep in mind it was a rush job)

bbd Inc.

the link to my company is at the bottom of the page
RONIN-1 said:
lol... it's far from complete but here....

(keep in mind it was a rush job)

bbd Inc.

the link to my company is at the bottom of the page
so you did all of that page? the intro and everything in there? pretty nice, very clean site, I wanna get more into web programing, but the project I get now are just, well, boring.
this is what i'm working on now, but the damn company keeps changing their mind about what they want. oh yeah, only one part of the site has sound, but hey, that's what they get, I work only 3 days a week now, so they'll have to wait.
www.aiagotgames.com/Movie4.html
MKX-R said:
so you did all of that page? the intro and everything in there? pretty nice, very clean site, I wanna get more into web programing, but the project I get now are just, well, boring.
this is what i'm working on now, but the damn company keeps changing their mind about what they want. oh yeah, only one part of the site has sound, but hey, that's what they get, I work only 3 days a week now, so they'll have to wait.
www.aiagotgames.com/Movie4.html
Yeah, I did all that myself... all the VB programming... all the flash... everything....

but last week I partnered up with 2 other guys for my company... so now we can all share the workload on future projects....

I know what you're saying about companies changing their minds... trust me... you don't even understand how many times I had to redo this site. It's brutal... I almost wanted to jump off a building cuz they kept changing shit... I'd write all this code... then have to scrap it, redo the database... etc etc.... Becuase firt they wanted all flash... and they wanted 3d flash.... so I started that... then when i was half way done... they wanted something else... it's brutal.... lol :mad:

hey your flash is pretty good still... I see you have some 3d spinning shit in there....

Anyway, that company "bbd" referred a lot of business my way so atleast I'm happy for that :D

EDIT: maybe we can help each other out on future projects, since you're Mr. Coldfusion :D

We even opened up an office in Toronto for Our Company :)
See less See more
RONIN-1 said:
Yeah, I did all that myself... all the VB programming... all the flash... everything....

but last week I partnered up with 2 other guys for my company... so now we can all share the workload on future projects....

I know what you're saying about companies changing their minds... trust me... you don't even understand how many times I had to redo this site. It's brutal... I almost wanted to jump off a building cuz they kept changing shit... I'd write all this code... then have to scrap it, redo the database... etc etc.... Becuase firt they wanted all flash... and they wanted 3d flash.... so I started that... then when i was half way done... they wanted something else... it's brutal.... lol :mad:

hey your flash is pretty good still... I see you have some 3d spinning shit in there....

Anyway, that company "bbd" referred a lot of business my way so atleast I'm happy for that :D

EDIT: maybe we can help each other out on future projects, since you're Mr. Coldfusion :D

We even opened up an office in Toronto for Our Company :)
ah, those companies are the worst, they don't realize that you have to re-program everything (a lot of times) in order to change one darn thing on the page.

ok, on thing though, I'm not a coldfusion guru, so don't expect anything too fancy :) I just took some coldfusion seminars, and played around a little, I had no request to make a coldfusion page yet.
but if you need any fancy 3D graphics, I'm game :) or some heavier programing in flash, I can do that too.. (not too heavy though hehe)
MKX-R said:
ah, those companies are the worst, they don't realize that you have to re-program everything (a lot of times) in order to change one darn thing on the page.

ok, on thing though, I'm not a coldfusion guru, so don't expect anything too fancy :) I just took some coldfusion seminars, and played around a little, I had no request to make a coldfusion page yet.
but if you need any fancy 3D graphics, I'm game :) or some heavier programing in flash, I can do that too.. (not too heavy though hehe)
Trust me, at least the lil' coldfusion u know is a lot more than I know.... As for flash and 3D, I have a guy who does strickly 3Ds max and Maya, and knows flash and director too... so I'm ok in that department..... but with ur bit of coldfusion knowledge, etc etc, that's good enough to collaborate on a few things... I have about 20 clients right now that I gotta finish work for, but it's not all web work, some are CD's (animations on CD's etc), and others are 3D animated ADS etc.... it's ok know, we can handle it, but eventually we're be contracting people we know for help....

....anyway... enough of that. :D
RONIN-1 said:
Trust me, at least the lil' coldfusion u know is a lot more than I know.... As for flash and 3D, I have a guy who does strickly 3Ds max and Maya, and knows flash and director too... so I'm ok in that department..... but with ur bit of coldfusion knowledge, etc etc, that's good enough to collaborate on a few things... I have about 20 clients right now that I gotta finish work for, but it's not all web work, some are CD's (animations on CD's etc), and others are 3D animated ADS etc.... it's ok know, we can handle it, but eventually we're be contracting people we know for help....

....anyway... enough of that. :D
ah, gotcha,..

well, hey, it's good to know people who can do things..
I used 3ds max mostly for that flash site, now I'm playing around with Plasma (by Discreet) it's kind of like 3ds max, same interface and all, but it has a built-in rendered for flash (very nice) and it can render shadows from multiple sources for flash too (VERY nice). and the good thing, it can also render regular images, for a fraction of price of 3DS max. :)
MKX-R said:
ah, gotcha,..

well, hey, it's good to know people who can do things..
I used 3ds max mostly for that flash site, now I'm playing around with Plasma (by Discreet) it's kind of like 3ds max, same interface and all, but it has a built-in rendered for flash (very nice) and it can render shadows from multiple sources for flash too (VERY nice). and the good thing, it can also render regular images, for a fraction of price of 3DS max. :)
damn, I just got Plasma last week..... haven't really played with it yet but i heard some good shit about it too....
blitzkrg said:
to declare a pointer, it's as simple as:
int *ptr;
<variable type> *<name of variable>;


now pointers basically store memory addresses. so to point a pointer to a variable, you'll have to pass it the address of the variable. to get the variable's address, you use the ampersand (&) operator.

for example, create an integer called x:
int x;

now assign it a value of 4:
x = 4;

next declare a pointer variable of int type:
int *ptr;

now you can give ptr the memory address of x:
ptr = &x;

run the following program. you'll get an idea of the difference between the ampersand and no ampersand:
#include <iostream.h>

void main()
{
int x; // create an integer variable called 'x'
x = 10; // put value of '10' into variable 'x'

cout << "the value of 'x' is " << x << endl
<< "the memory address of 'x' is " << &x << endl;
}


last but not least, to pass the address of the variable, leave the asterisk in front of the pointer out:
WRONG: *ptr = &x;
RIGHT: ptr = &x;

so w/ that in mind, you tell me:
using the assignments from above the sample program (where x = 4), what does cout << *ptr; give me?
and what does cout << ptr; give me?

good luck.
very well put, although i'm using it for c, not c++, but i get the concept. thanks for all the help. :cool:
1 - 20 of 21 Posts
This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.
Top