why pointers?? why? D:

The Partridge Family were neither partridges nor a family. Discuss.
lloganm
Posts: 87
Joined: August 10th, 2012, 11:26 pm

why pointers?? why? D:

Post by lloganm » November 14th, 2012, 2:11 am

So I finished beginner lesson 17, and attempted the homework. However, I was confused as to why the GetString function had to have the parameters of (char* buffer,bufLength). I made my function just using bufLenght and I declared a buffer within the function... So why would we have to have (char* buffer) in the parameters? This probably has to do with me not understanding pointers, so if someone could explain that'd be awesome. Also, if someone knows a good youtube video that explains pointers(no offence chili) that'd be good too, thanks!

adabo
Posts: 154
Joined: October 27th, 2012, 3:28 am
Location: Houston, Texas

Re: why pointers?? why? D:

Post by adabo » November 14th, 2012, 2:59 am

Just for the sake of clarity, before I start an elaborate explanation, could you paste the block of code you're referring to?

lloganm
Posts: 87
Joined: August 10th, 2012, 11:26 pm

Re: why pointers?? why? D:

Post by lloganm » November 14th, 2012, 3:01 am

void GetString(char* buffer, int bufLength)
{
int index = 0;


for(char c = getchar(); index < (bufLength - 1) && c != '\n'; index++)
{
{
buffer[index] = c;
c = getchar(); //program stops here for program input
}
}
buffer[index] = '\0';
}

adabo
Posts: 154
Joined: October 27th, 2012, 3:28 am
Location: Houston, Texas

Re: why pointers?? why? D:

Post by adabo » November 14th, 2012, 4:01 am

Alright cool. I'm working on a tutorial. Hope you're not rushed because I don't work super fast. I'll have it done before this evenings done. I have really simple approach to pointers that should ,at the least, help.

In the meantime, I know simple youtube search of something like "introduction to pointers" or "c++ pointers" or whatever you think... "pointers for noobs or beginners"..

lloganm
Posts: 87
Joined: August 10th, 2012, 11:26 pm

Re: why pointers?? why? D:

Post by lloganm » November 14th, 2012, 4:17 am

oh wow haha well thanks, I didn't think you would actually make a video for me :D that's awesome

adabo
Posts: 154
Joined: October 27th, 2012, 3:28 am
Location: Houston, Texas

Re: why pointers?? why? D:

Post by adabo » November 14th, 2012, 5:55 am

Check your pm D:

User avatar
thetoddfather
Posts: 338
Joined: October 1st, 2012, 9:53 pm
Location: Canada

Re: why pointers?? why? D:

Post by thetoddfather » November 14th, 2012, 7:04 am

Mind if I have a look too? Always looking for more info on pointers/refs

adabo
Posts: 154
Joined: October 27th, 2012, 3:28 am
Location: Houston, Texas

Re: why pointers?? why? D:

Post by adabo » November 14th, 2012, 7:22 am

I didn't finish the video. In his pm I just told him I'd skype him because my screencast wasn't going as planned.

If you want a skype session, let me know: abelgut

Muttley
Posts: 39
Joined: October 19th, 2012, 6:00 am

Re: why pointers?? why? D:

Post by Muttley » November 14th, 2012, 5:18 pm

I think the most important right now is understand the basic of pointers, doesn't matter why they are useful or necessary.

I read this in a book,
"If you don’t get it, just start using these pointers and give yourself time. You’ll slowly come to understand."
Here is an example of how I understand pointers ( sort of )

int someNumber = 12;
int* pointer = &someNumber; // Now the pointer points to someNumber address.

// Result on screen.
someNumber value is " 12 ".
pointer value is " 3602856 ". // This weird number is the address in memory of someNumber.

// Now lets print this with the Dereference operator *.
*pointer value is " 12 ". // When you use the Dereference operator is like "I dont want your
address anymore bro! I want your home and your family!


// So, " pointer " itself is the address,
// And " *pointer " is the real VALUE of you are pointing to.

// Now if you want, you can assign another value to your pointer and forget about that dude
and his family.


int dudeAge = 21;
pointer = &dudeAge;

// print
dudeAge is " 21 ".
pointer value is " 3209400 ".
*pointer value is " 21 ".
I hope it help. ;)

lloganm
Posts: 87
Joined: August 10th, 2012, 11:26 pm

Re: why pointers?? why? D:

Post by lloganm » November 14th, 2012, 6:02 pm

That did actually help! But that quote is right, I think I'll go google some projects/problems involving pointers and start using them. Thanks man

Post Reply