why pointers?? why? D:
why pointers?? why? D:
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!
Re: why pointers?? why? D:
Just for the sake of clarity, before I start an elaborate explanation, could you paste the block of code you're referring to?
Re: why pointers?? why? D:
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';
}
{
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';
}
Re: why pointers?? why? D:
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"..
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"..
Re: why pointers?? why? D:
oh wow haha well thanks, I didn't think you would actually make a video for me that's awesome
Re: why pointers?? why? D:
Check your pm D:
- thetoddfather
- Posts: 338
- Joined: October 1st, 2012, 9:53 pm
- Location: Canada
Re: why pointers?? why? D:
Mind if I have a look too? Always looking for more info on pointers/refs
Re: why pointers?? why? D:
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
If you want a skype session, let me know: abelgut
Re: why pointers?? why? D:
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,
I read this in a book,
Here is an example of how I understand pointers ( sort of )"If you don’t get it, just start using these pointers and give yourself time. You’ll slowly come to understand."
I hope it help.
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;
dudeAge is " 21 ".
pointer value is " 3209400 ".
*pointer value is " 21 ".
Re: why pointers?? why? D:
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