Ask Experts Questions for FREE Help !
Ask
    BIGBOPPER's Avatar
    BIGBOPPER Posts: 351, Reputation: 28
    Full Member
     
    #1

    Mar 21, 2009, 03:45 PM
    Is there an easy tutorial for C++?
    I am studying it in college, and was understanding it up until now. I need an online 'tutorial for dummies' that gives examples of code, and easy explinations on how they work, when it is used, ETC..
    I am using Visual Studio 08' as my compiler, and I understand that there is a difference in the language from that compiler and others, like Bloodshed Dev++.
    Can anybody help?
    Thanks.
    Scleros's Avatar
    Scleros Posts: 2,165, Reputation: 262
    Hardware Expert
     
    #2

    Mar 21, 2009, 04:58 PM
    Try C++ Language Tutorial. What are you having problems with?
    BIGBOPPER's Avatar
    BIGBOPPER Posts: 351, Reputation: 28
    Full Member
     
    #3

    Mar 21, 2009, 10:23 PM

    I feel stupid, but keep in mind I'm an "old dog" with this. I am getting stuck on functions, and loops.
    I remember the days of basic, especially "TI basic".
    All this stuff is new to me.
    Scleros's Avatar
    Scleros Posts: 2,165, Reputation: 262
    Hardware Expert
     
    #4

    Mar 22, 2009, 02:17 AM
    Quote Originally Posted by BIGBOPPER View Post
    I am getting stuck on functions, and loops.
    I remeber the days of basic, especially "TI basic".
    Loops

    If you mean the "BASIC" language in Texas Instruments calculators, that's more of a subset of BASIC. It's BASIC-ish. Are you conditioned to loop by using GOTOs back to a label or line number ahead of the statements to be repeated? If so... stop it. :)

    GOTOs make code hard to maintain. Most C/C++ loops consist of a block of code with a condition that is tested either at the beginning of the block or at the end of the block that determines whether to repeat the block.

    There is...

    Code:
    do {
    
     /* ... bunch of stuff ... */
    
    } While ( ThisExpressionIsTrue );
    or

    Code:
    While ( ThisExpressionIsTrue ) {
    
    /* ... do bunch of stuff ... */
    
    };
    See the Control Structures section of the tutorial I linked in my prior post. There is also a for loop typically used for looping a set number of times while a counter is incremented.

    Functions

    Are nothing more than a group of statements that are given a name and then referenced elsewhere in the program by the name:

    Code:
    void MyLongInvolvedFunction(void);
    
    int main(void) {
    
    /* ... do some stuff ...*/
    
    // Call my long involved function...
    MyLongInvolvedFunction();
    
    /* ... do some more stuff ... */
    
    // Call my long involved function, again...
    MyLongInvolvedFunction();
    
    /* ... do yet more stuff ... */
    
    // Call my long involved function, yet again...
    MyLongInvolvedFunction();
    
    };
    
    void MyLongInvolvedFunction(void){
    
    /*
    My long involved function is 500 lines of code.
    I'm too lazy to type 500 lines of code in my
    main routine every time I need it, so I stick
    it in this function that I can call by a short name.
    */
    
    /* ... do some seriously complicated stuff ... */
    
    };
    Info (parameters) can also be given (passed) to the function to play with when it is called.

    Code:
    /*
    Following function declaration gives the function
    an int value and a long value to play with,
    function then returns an int when done.
    */
    int MyFunction(int MyInt, long MyLong);
    The concept of scope comes into play here. In BASIC it is typical for all variables to be global in scope, meaning they can be referenced anywhere in the program regardless of the code module (file) they are declared in, or subroutine they are used in. In C/C++, the variables MyInt and MyLong in the example above exist only within the function. When the function is called with a another variable such as:
    Code:
    MyFunction(Count, BigNumber);
    any changes MyFunction makes to the value of MyInt (which begins life with the value of Count) will not be reflected in the value of Count. The variable Count and MyInt have separate memory locations when the program executes. For MyFunction to directly change Count, the memory address of Count would be passed as a pointer reference like:

    Code:
    int MyFunction(int *MyInt, long MyLong);
    but that's another discussion.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

A Good PHP Tutorial [ 6 Answers ]

Does anyone know of a good, easy-to-understand, free PHP tutuorial that I can download and learn from? I am highly interested in utilizing the PHP server my website is hosted on. Thank you.

Need Sewing Tutorial [ 1 Answers ]

Hello All. I need a really good tutorial for how to teach someone to sew that has never sewed... Also Maybe a creative thing that men and women would enjoy doing. Any Suggestions? Let me know. Thanks


View more questions Search