Added: 4 years ago
From: reconnetworks
Views: 113,233
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:
see all

All Comments (191)

Sign In or Sign Up now to post a comment!
  • *5 years in the future*

    When does tutorial 6 come out? :D

  • @tedtdu You don't need to 'return' a value from the function because that's what the pointers are for. You can only 'return' one value from a function so instead you can use pointers. When you assign a value to a pointer (even in another function) it will assign that value to the variable which it points to. So the user's input assigns that number to the pointer, which automatically sends the value to the variable in 'main'.

  • Since "pointerfunction" does not return, how can the firstpointer and secondpointer equal to the number using inputs?

  • so basic hahaha

  • What's the meaning of the asterisk in your program.

    Please just mail me your answers. Thanks..

  • @eminemchu43 rtfm

  • firstpointer and secondpointer are not pointers- they are variables, their ADDRESSES are pointers.

  • ok i understand now :D btw i also finally learned what endl; does cuz you stoped using it alot in this one :)

  • ewww, he's using system("pause") such a windows dependent function.

  • Nice one, 4 was a bit confusing and long but I think this cleared it up a little

  • Do you know how to like run a Runcount which means the timer would run like this:

    01 02 03 0 40 50 60 07 08..

    side by side after 1 sec?

  • lookup for loop thats probably the first program that will show up

  • Thanks for this. Pointers have now stuck thanks to you, and I shall now move on :)

  • My programming professor never explained this well. I didn't understand this concept till my second c++ quarter when I had a better professor. Will you be showing how to create simple games in the future?

  • Could you possibly say "out and about, i pout with a trout" in the next video?

  • @XXxZAKKxX wtf?

  • @benny21003 I like canadian accents >_>

  • So wat happened to the "big vid" u promised was going to come out?? *disappointed*

  • before explaining pointers it would be easier to explain scope first, then you can explain how they can remove the limitation of scope this way it will hopefully make them easier to understand and why you would use them. NOT critisizing your Vid but this would probably make it easier for you to explain

  • can i make game hacks with this programme??

  • @Raytzuno Learn memory editing with c++ and YES you can.

  • *sigh*

    I miss GOSUB and GOTO

  • @ManOfMeans lol what is that, basic?

  • lol Yes, actually

  • can u help with this

    each time he completes a modification, he records the vehicle's mileage before driving, the mileage after driving and the amount of fuel consumed for the trip.

    Charlie has asked you to write him a program that calculates his fuel efficiency in miles per gallon. Create the IPO Model and pseudocode algorithm for this program. Include error checking such that the mileage of the vehicle after driving cannot be a lower value than that entered for the mileage before driving.

  • i luv pie :3

  • just a suggestion : please use comments on your code so we can follow them better instead of saying "you already know".

  • Weird number? MY MOTHER WAS A SAINT!

  • LOL you could do like this too and its much easier:

    void functionname(BLAH HERE)

    { // Stuff here

    }; <- adding a semicolon would declare it so you dont have to voiding it twice!!

  • You dont need to do a semicolon there. In fact I think you would even get a compile time error for doing it, since it is a function not a class. You can just make the curley braces and write the content in between and then call it. What he is doing is declaring it first in the top and the definining it in the bottom, something I dont prefer doing but many prefer to do so.

  • But thats beside the points. The main thing is the guy is not working with pointers per se. Int firstpointer; This isnt a pointer as the video suggests. Thats just an int variable.

    int *p1;

    int thirteen= 13;

    p1 = &thirteen;

    Now we have a pointer, pointing to thirteens memory store.

    and then the pointer is passed raw as an argument to the function:

    pointerfunction(p1);

    not with * or &.

    Cheers.

  • Or we could even skip the variables altogether with lets say:

    int *p1;

    p1 = new int;

    *p1 = 13;

    Now the pointer points to a memory location which holds 13 and you can manipulate the number in that memory location just as you would if it had a variable attached to it.

  • You don't add a semicolon after declaring a function.

  • Yes you do.

  • Nice job, pointers are definitely one of the hardest things to comprehend in C++. I still only have a basic understanding of them. You did clear some stuff up for me.

  • is this what The Behemoth uses to make games?

  • dont you have to put /n at the end of statements?

  • '/n' is a newline character.

  • Its just another way of ending a line. Just like endl

  • wat exactly does this program do

  • I need help trying to build a code that will show a temperature table and prompt the user for beginning end and increment. any ideas?

  • Can you describe your program a little better?

  • /n ftw

    endl = boo

  • Use both

  • Ive been learning c++ for a while and i'm not close to you, but i don't get and haven't ever needed to use endl;

  • It's just to make it look better, going a line down in the console

  • As you can see at 5:19, the 12 is next to "Press any key... Blabla", when you put an endl; there it would look like

    "12

    Press any key to continue..."

  • so its just like putting " blah blah blah /n"

  • shut up!!!!!!!! asshole!!!!!!

  • I'm glad you put the asterisk beside the type name rather than the variable name. Much more intuitive.

  • Yo! great vid..i have a question though...does that mean that the pointers are exactly the same thing as formal parameters in a function's argument??

  • Please, teach us how to program with classes

  • nothing on virtual classes?

  • im teaching simple console applicatons... its not improper practice.

  • @reconnetworks Do you have any C++ GUI Tutorials?? All I can find are console, thanks, =).

  • Can you show us how to do a operator overload using a string with an array. Like a complex number class using the +, -, *, /, =, ==, and <<.

  • what software you used? is that dev c++?

  • that's Microsoft Visual C++

  • no its dev C++ he says in the first vid

  • You're a stupid dumb ass, that's Visual Studio. Get A What.

  • yea your right, but he does say hes using devc++ in the first vid... get a what? lol wtf does that mean where your from lol

  • I'm from CannabisLand.

  • Don't use system("PAUSE")

    use getchar

    cmon, educate the masses!

  • Theres nothing wrong with system("PAUSE");

    You can use the cin.get() function but it's not needed

  • What about the fact that it will only work on Windows?

  • Yeah, but I was talking in context of the video, in which he is programming a Windows machine.

  • there's more wrong with it than that but I'm lazy so I won't fight you, you can program anyway you prefer though. It's just not considered good practice.

  • I'm not looking for a fight, just knowledge.... or something like that

  • Oh me niether I'm just saying I didn't mean to look like I was telling him how to program, I just reread that and thought it sounded kinda meanXD anyways well met!

  • You might want to explain Scope, if you're going to explain pointers, since they are the main reason that people even USE them.

  • Pointers are simple..........but Nodes and linklists DOMINATE ME :'(

  • Dude you should explain that an Pointer is just an address to the memory and if you do not declare it as a pointer its getting dynamicly allocated which is also deallocating when the function returns.

    Maybe you should go deeper into malloc/free for people so they understand why use them and when.

  • Pointers are cool in C. Linked lists and recursive binary trees. In C++ I would just use the classes they have written for you. Plus your still writing functions in C. Where is the C++? Write a class with some data and member functions.

  • I know your not in youtube much but can anyone tell me how to make that symbol for the address.

    4 line of int main().

  • Hey matie, since no1 seems to help you...

    The symbol is &

    ;)

  • u using notepad++? looks like it. if so same

  • I wasn't asking for your email? :)

    I was wondering if this reconnetworks guy will post more stuff on OOP of C++.

    OOP = object oriented programming

  • I checked out your website but couldn't find your email or anything to contact you with?

    how come you don't put more videos?

  • Hi,

    thanks for these tutorials.. are u going to put some tutorials on OOP part of C++?

  • whats OOP?

  • Object Oriented Programming.

  • Very helpful. Thank you.

  • hei. are you going to continue with the tutorial series or not? :-S

  • What do you with all that tiping and numbres ?? what do you get a progarm a calculetor ?? how do you get from this to let say mario in NEs . can someone explain that to me ?

  • thnk you Jim

  • int firstpointer, secondpointer, result;

  • Isn't this called pass by reference using pointers. Note also, the address of operator is different to a reference.

  • I tried putting in a program I made but everything I tieped gave a error! Please send message!

  • just something about the compiler, why can't i link iostream into my projecT?

  • explaining pointers is really hard... but i think u did a pretty decent job. i now understand them a lot better.

  • Explaining pointers is easy, understanding them is the hard part.

  • well thats what i meant, its hard to explain them so that ppl can understand. i guess u just have to do them a few times... my teacher drew a diagram and that helped ALOT.

  • ahh, good, your teacher... Wish i had a teacher, would probably make things make a lot more sense. 15 doing this on my own... pretty hard if you ask me =( but i do understand pointers being used in functions now, thanks reconnetworks :)

  • Likewise, pointer's a tough subject for me to grasp (16), I'm used to managed code, .NET, etc.

  • i didn't quiet get it :S...

  • new site is reconnetworks . net

  • ok if i had a chessboard declared as 0 - 63 squares, and i used a pointer array of 16 to hold the locations of only the white pieces on the board this qould not be a good analogy cause it is not the same idea actually i am just rambling cause i don't really care for pointers ..yet

  • can we adress with complex pointers ...like &&&xds

  • You can't use multiple address operators; However you can create a pointer to a pointer, or a pointer to a pointer to a pointer, like this int*** p; Then you can make that point to a pointer to a pointer, which in turn can point to a pointer; int*** p1; int** p2; int* p3; int data = 5; p1 = &p2; p2 = &p3; p3 = &data;
  • Pointers are a pretty complicated thing, it takes a while to really figure out - so dont get depressed when you dont learn it instantly.

    GL teaching 'classes' on youtube :P (Not classes as in classrooms)

  • You forgot to mention why you would use pointers. It works with the original data instead of a copy. Unlike passing by value, pointers actually alter the data. It's also very important to mention the importance of const.

  • New website is reconnetworks&#46;net&#47;foru­m

    See you there, Icemens =)

  • good

  • for anyone who is interested, the new site is reconnetworks(.)net(/)forum

  • нэпонатно

  • you guys cannot correct what this guy is doing... he is trying to make a video for people to begin to use c++ programming

  • He's teaching C++ and in this situation, pointers should not have been used. He should have references instead.

  • that is very true.. it looks more like c

  • Java is quite inefficient, but simpler! C++ is efficient for intensive code!

  • you forgott " excuse me " when u *host* xD hhaha u said that on tut 1

  • very useful stuff listen to this guy!

  • Your pointerFunction is useless...... you use just integer variables. result = int1 + int2; ... ;D .. but you can see the point of your video if you already have progamming skills... make another example where pointer function would do something in 'main'... :P

  • I think it would be better instead of typing "cout << endl;" you could just type "cout <<"\n ..."

  • endl flushes the buffer.

  • Oh now i understanded what you wanted to tell us.

  • A very wise C programmer once told me...

    "There are two types of C programmers, ones that don't know pointers, and the successful ones that do."

  • So let me get this straight. That * thing means refers to the address of whatever variable name it precedes (pointer). The & beside the variable name means the address of where the variable stores data?

  • no;

    * means the value pointed to by the pointer

    and & means the address of something.

    when you initialize a pointer, say int*pointerx;

    in that case, the * just means pointer

  • that was at juelz85

  • This is where pass-by-reference is needed. If you actually *want* the called function to change main_x and main_y, you will have to pass it the "address-of" or "pointer-to" the actual variables so that it can change them.

    In my example, f2 is actually designed in a way so that it can change the variable that was passed in.

    To answer Xyaon's question, if you pass by-value instead of by-reference, the function will only modify it's local variables and the original variables will remain the same.

  • int main(void)

    { int main_x = 4; int main_y = 5; // You can call f1 like this f1(main_x, main_y); // OR like this f1(4, 5); // You have to call f2 like this f2(&main_x, &main_y);

    }

    When a parameter is passed to a function, the called function makes a copy of that parameter and stores it in another local variable. In the above example f1 stores 4 in f1_x and 5 in f1_y as soon as it starts executing. Changing f1_x and f1_y within f1 do NOT change main_x and main_y.

  • For example:

    void f1(int f1_x, int f1_y); // By-value

    { f1_x = 100; // Change only local variable, no effect on caller's variable f2_y = 200;

    }

    void f2(int* f2_x, int* f2_Y); // By-reference

    { *f1_x = 100; // Change the caller's variable *f2_y = 200;

    }

  • In this video, you need pointers because you want the "called" function to be able to modify the variables that actually belong to the "caller" function.

    There are two ways of passing a parameter to a function. By-value and by-reference.

  • So, i still don't see why someone uses pointers. I kinda get how to use them. How does using pointers do anything for you in this example.

  • I was wondering , im still not to sure about why to use pointers. ( Sorry im a PHP programmer so i havn't really understood pointers:P )

    But isnt it just the same to use:

    pointerfunction(int var1, int var2){ cin >> var1 >> var2;

    }

    and ofc call it without all those pointers ?

    Sorry for my noobness

  • int main()

    { int* firstpointer = NULL;

     int* secondpointer = NULL; pointerfunction(a, b); return 0;

    }

    :) You should really teach proper use of pointers; check if the pointers are valid. If they're not, then return early.

  • If you don't define pointers, then you can get a value of anything, even the value of a string in a word document, and changing it.

  • I think that you're referring to dangling pointers... If you don't define a pointer it is initialised to 0xCCCCCCCC and if you attempt to dereference it (in a good IDE like VS) you'll get a "Run-Time Check Failure".

  • Just incase anyone learning is curious, these are two ways that dangling pointers can be produced (something that you should AVOID):

    int* i = new int(3);

    delete i;

    *i = 5;

    or

    int* f()

    { int temp = 5; return &temp;

    }

  • Al of your tutorials are great noobs like me :D Thx, but I dont still know the pointers so good :)

  • Cool...much better now :D when's the next one??

  • this dude is keep talking in the video but saying nothing useful...he is confused for himself. can anyone tell this dude stfu?

  • Shaddup!

  • i think that bookgekgom have right, if u want to learn programming this noob ain't gonna help ya'

  • He was nice to listen to and explained a lot of stuff in clear English, but it was kind of frustrating to write 5 lines of code only to hear "Whoops!" and then have to delete it.

    Also, where is this huge tutorial #4 was "preparing" us for? I'm kinda dissapointed :\.

    Oh well, pretty good tutorials :P.

  • i see that truth is hurting some people :>

  • I just want to point out this code is rout with poor practices. One of these being hungarian notation. Make sure you do NOT use hungarian notation, it is a sign of very poor programming. If there is any confusion about what types your variables are or if the function you're working on is nested so deeply and is multiple screens long, it is coded incorrectly and needs to be re-done. Never should such a hackish notation be adopted to fix the problem.

  • stfu noob.

  • lol k

  • you are right. i do not understand why ppl are still using stupid hungarian notation although stuff developed so much not need HN to organize shits..:/

  • guys is visualc++ 2005 is much better then 2003 ?? cuz i've download the 2005 but i think it has some console missing :S

  • i dont really think theres a better, just maybe easier to use. im using Borland C++ 5.5.1 (which uses command prompt for compiling and editing) and i can follow these fine.

  • i use visual C++ to use c++

    and blueJ for Java, (good starter program)

  • why didn't you use references since this is a c++ tutorial?

  • how come everything i do doesnt work when i have done everything exacly how u said

  • coz ur a noob lol!!!

  • i use DEV also it is BAAAD

  • Dev is good. You just need to know how to use it. When you start a project, you don't have to do all tnese things like you need to do with microsoft. and when you get in to "window's programming" you don't need to use the stupid runtime files in your projects. (when you send it out)

  • oh wait he said in his first video it was dev C++ but my dev C++ looks different um strange

  • Looks like it's Visual Studio...

  • It is.

  • What name of IDE ?

  • visual studio 2005

    someone correct me if am wrong but i dont use it

    i use dev C++

  • Hey.. good video's.. are you going to put anything up on C++ Classes and good working example of its use. Would be very much appreciated. Thanks again for your time.

  • Pointers are important to keep in mind; however, ALWAYS think to yourself: "Is this going to be the quickest, most efficient way to program this?" Remember that there are always a billion ways to accomplish something in programming, the trick is finding the simplest way to do it.

    What's being displayed here is a simplified explanation of syntax and usage, not a viable solution to this specific issue.

  • Pointers are important tools when working with an highly compliant object-oriented (OO) language like C++. One of the fundamentals of OO is encapsulation which prevents one function from interfering with another including accessing or manipulating data. A pointer foils this by allowing another function to access the specific memory location the datum is stored in. Since it is referencing a memory location and not a variable in the program, it is not limited by OO.

  • I don't see the point of using pointers, I mean, you could´ve used the function just with the variables you declared before. I can only imagine using the pointers if i want to know the address of the variable I´ve declared, but no other. well, I´m an amateur at C++, and I´m not going to learning more about it, but I would like to know a really important use for the pointers.

  • Thanks for all tutorials!

    But I've got a question, Do you know how to make a window in C++? I mean not in a console.

  • Honestly, if you're looking at making a windows application, I'd recommend Visual Basic. You can get a free version from Microsoft (Visual Basic Express). This will work for most development needs and is quicker to develop in than C++.

  • pointers are the same thing as variables when they are local, so I dont understand the question any more... :/

  • To change an int to a char you can use static_cast, read up on it or ask about it on reconnetworks dot com

  • hey... i know how to change an int to char... im talking about changing on pointer type to another

  • thanks, am starting to catch on the difference between the two laguages of C and C++. i am new to c and i have not notice the c++ is a little different.

  • hey reconnetworks i need your help on something...

    do you know how to convert an int* to char*?

    I tried using a reinterpret_cast, it converts to a different pointer but the value it points to changes.

  • edfast46 ...C is basically C++...just a modified C....

    if you really want to learn C++ or even C... i can show you a way you can learn about 95% of the language in a week... 2 days if you have some programming experience. i have been programming in C++ for 7 years on and off so i know it very well;

  • c++ is just a superset of the c language, and is object oriented. You have to give specific examples of your problems if you want an answer :/

  • @reconnetworks actually C++ is not object oriented its multiparadigm meaning it supports many different styles of programming and not just object orientation its actually a completely false misconception calling C++ object oriented

  • solve

  • ever try to mix C with C++ and try to solvve any programs with the two.

  • alot of these are cross compatible.

  • Question? Is C to old to learn and is it worth it to learn it now?

  • ok, thanks am stuck on pointers and arrays passing to the functions can you do a video on that in C pragramming, if not thanks.

  • I can teach my tutorials however I want, thanks.

  • You left out saying what is the function prototype,and the function header, and how the arguments pass through the function header as function peramaters, do the video right if your going to teach c++.

  • Hey, thanks for the awesome tutorial... keep it up man...

  • no problems man, thanks for the compiment! :)

  • Wow, I know HTML, CSS, JavaScript, DHTML, and BAT and I find C++ pretty confusing. This is definetally gonna take some time to learn but not that long with these awesome tutorials xD

  • waltermodel43 is a classic flamer on youtube. He flames in hope to get to you. It's too bad there is no career for flaming because people really act like it's there job to piss people off... What a c-flamer.