Results 1 to 9 of 9
  1. #1
    P0SEID0N's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    KFC
    Posts
    318
    Reputation
    10
    Thanks
    24
    My Mood
    Lurking

    Learn how to code C++ || Day 3 - Variables and Date Types

    Lesson #3 - Variables/Data Types

    The first thing i'm going to do is take a little experiment off here:
    I want you to remember:
    A = 6
    B = 9
    C = 3
    D = 3
    A + D = 9
    E = A + D
    C = E
    E - 6 = B

    Now what does A + B x C + E equal? Finding it a bit hard to remember? Thats why we have Variables.
    What you have just done with your memory is the same as what a computer can do with variables. The same process can be done in C++ like this:
    Code:
    A = 6
    B = 9
    C = 3
    D = 3
    E = A + D
    C = E
    E - 6 = B
    We can define a variable as a portion of memory to store a determined value. Think about it as a small block of memory, you can write on it, erase it, make it bigger or smaller, but all the time just calling it by its identifier.

    The identifiers in that example were all single letters, A, B, C, D and E. Spaces or punctuation marks or symbols cannot be part of an identifier. Only letters, digits and single underscore characters are valid. Variable identifiers always have to begin with a letter or an underscore.

    Something else that you have to consider when inventing your own identifiers is they cannot match any keyword of the C++ language or your compiler's specific ones, which are reserved keywords.
    Standard reserved keywords are:
    [php]
    asm, auto, bool, break, case, catch, char, class, const, const_cast, continue, default, delete, do, double, dynamic_cast, else, enum, explicit, export, extern, false, float, for, friend, goto, if, inline, int, long, mutable, namespace, new, operator, private, protected, public, register, reinterpret_cast, return, short, signed, sizeof, static, static_cast, struct, switch, template, this, throw, true, try, typedef, typeid, typename, union, unsigned, using, virtual, void, volatile, wchar_t, while[/php]

    Additionally, alternative representations for some operators cannot be used as identifiers since they are reserved words under some circumstances:

    [php]and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor, xor_eq[/php]

    Remember C++ is a case sensitive language so Identifier is not the same as identifier or iDentifier.
    There are many data types that can store many different things. From integers(whole numbers) to Characters or Strings. Here is a list of some.
    [IMG]https://i755.photobucke*****m/albums/xx191/_-_-_JAMES_-_-_/DataTypes.jpg[/IMG]

    If we want to use a variable, we must first declare it. You do this by putting a valid data type followed by your identifier. For example:
    [php]int cat;
    char dog;[/php]

    If you are going to declare more than one variable of the same type, you can declare all of them in a single statement by separating their identifiers with commas. For example:
    [php]int a, b, c;[/php]
    You DON'T need to do
    [php]int a;
    int b;
    int c;[/php]

    The integer data types char, short, long and int can be either signed or unsigned depending on the need. Signed types can represent both positive and negative values, unsigned types can only represent positive values (and zero).If we do not specify either signed or unsigned most compiler settings will assume the type to be signed.

    An exception to this rule is the char type, which is considered a different data type from signed char and unsigned char. You should use either signed or unsigned if you intend to store numerical values in a char-sized variable.

    Short and long can be used alone as type specifiers. Short is equivalent to short int and long is equivalent to long int. The following two variable declarations are equivalent:
    [php]
    short cat;
    short int cat;
    [/php]

    Signed and unsigned may also be used in the same way.

    We will now look at the scope of variables.
    There are two types of variables we will look at Global and Local.
    Global variables can be referred from anywhere in the code, even inside functions, whenever it is after its declaration.
    The scope of local variables is limited to the block enclosed in braces where they are declared. If they are declared at the beginning of the body of a function their scope is between its declaration point and the end of that function. This means that if another function existed in addition to main, the local variables declared in main could not be accessed from the other function and the variables from the other function could not be accessed inside main.

    When declaring a regular local variable, its value is automatically undetermined. But you may want a variable to store a value at the same moment that it is declared. In order to do that, you can initialize the variable. There are two ways to do this in C++:
    [php]
    int a = 6;

    OR

    int a (6)
    [/php]



    We are now going to use all this in a program:
    Code:
    #include <iostream>
    using namespace std;
    //you can declare global variables here
    int rabbit = 1;
    int main()
    {
    //you can declare local variables here
    int dog = 3;
    int cat (4);
    cout << dog << endl;
    cout << cat << endl;
    cout << dog + cat << endl;
    dog = rabbit;
    cout << "we have now changed dog to rabbit" << endl;
    cout << dog;
    return 0;
    }
    The result should look like this:
    [php]
    3
    4
    7
    We have now changed dog to rabbit
    1
    [/php]

    Credits:
    www.cplusplus.com
    www.cprogramming.com
    Me
    Last edited by P0SEID0N; 04-15-2010 at 02:51 AM.

  2. #2
    [C]hosen-1's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    In my house >.>
    Posts
    729
    Reputation
    11
    Thanks
    50
    My Mood
    Psychedelic
    this one confused me.




    Respect List:
    - [RIP] тιмє
    - ReZaJwZ
    - Ghost
    - Coke
    - [MPGH]Omega
    - Shaunc
    - [MPGH] Petey Piranha

  3. #3
    skykrutch's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    357
    Reputation
    11
    Thanks
    66
    My Mood
    Bored
    I do'nt fucking understand anything

  4. #4
    mokkiller2's Avatar
    Join Date
    Feb 2010
    Gender
    male
    Location
    In front of a computer :D
    Posts
    298
    Reputation
    10
    Thanks
    25
    My Mood
    Yeehaw
    understood all, thank you !!!!

    !! RAISE MY HABAMON IF U ARE COOL !!



    THE BEST WAY TO DEFEND YOURSELF IS TO ATTACK






    I support Thieving Eh for the Publicist competition in CA section Thieving Eh vid is the first post right below Obama and Dave on the first page! https://www.mpgh.net/forum/7-news-ann...st-needed.html

    GO Thieving Eh






  5. #5
    P0SEID0N's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    KFC
    Posts
    318
    Reputation
    10
    Thanks
    24
    My Mood
    Lurking
    If it confuses you then try and do some of the practical work in it. eg. put my code in and see what it does. Then read over the theory again.

  6. #6
    theillon's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Posts
    2
    Reputation
    10
    Thanks
    0
    My Mood
    Tired
    Quote Originally Posted by P0SEID0N View Post
    Lesson #3 - Variables/Data Types

    The first thing i'm going to do is take a little experiment off here:
    I want you to remember:
    A = 6
    B = 9
    C = 3
    D = 3
    A + D = 9
    E = A + D
    C = E
    E - 6 = B

    Now what does A + B x C + E equal? Finding it a bit hard to remember? Thats why we have Variables.
    What you have just done with your memory is the same as what a computer can do with variables. The same process can be done in C++ like this:
    Code:
    A = 6
    B = 9
    C = 3
    D = 3
    E = A + D
    C = E
    E - 6 = B
    We can define a variable as a portion of memory to store a determined value. Think about it as a small block of memory, you can write on it, erase it, make it bigger or smaller, but all the time just calling it by its identifier.

    The identifiers in that example were all single letters, A, B, C, D and E. Spaces or punctuation marks or symbols cannot be part of an identifier. Only letters, digits and single underscore characters are valid. Variable identifiers always have to begin with a letter or an underscore.

    Something else that you have to consider when inventing your own identifiers is they cannot match any keyword of the C++ language or your compiler's specific ones, which are reserved keywords.
    Standard reserved keywords are:
    [php]
    asm, auto, bool, break, case, catch, char, class, const, const_cast, continue, default, delete, do, double, dynamic_cast, else, enum, explicit, export, extern, false, float, for, friend, goto, if, inline, int, long, mutable, namespace, new, operator, private, protected, public, register, reinterpret_cast, return, short, signed, sizeof, static, static_cast, struct, switch, template, this, throw, true, try, typedef, typeid, typename, union, unsigned, using, virtual, void, volatile, wchar_t, while[/php]

    Additionally, alternative representations for some operators cannot be used as identifiers since they are reserved words under some circumstances:

    [php]and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor, xor_eq[/php]

    Remember C++ is a case sensitive language so Identifier is not the same as identifier or iDentifier.
    There are many data types that can store many different things. From integers(whole numbers) to Characters or Strings. Here is a list of some.
    [IMG]https://i755.photobucke*****m/albums/xx191/_-_-_JAMES_-_-_/DataTypes.jpg[/IMG]

    If we want to use a variable, we must first declare it. You do this by putting a valid data type followed by your identifier. For example:
    [php]int cat;
    char dog;[/php]

    If you are going to declare more than one variable of the same type, you can declare all of them in a single statement by separating their identifiers with commas. For example:
    [php]int a, b, c;[/php]
    You DON'T need to do
    [php]int a;
    int b;
    int c;[/php]

    The integer data types char, short, long and int can be either signed or unsigned depending on the need. Signed types can represent both positive and negative values, unsigned types can only represent positive values (and zero).If we do not specify either signed or unsigned most compiler settings will assume the type to be signed.

    An exception to this rule is the char type, which is considered a different data type from signed char and unsigned char. You should use either signed or unsigned if you intend to store numerical values in a char-sized variable.

    Short and long can be used alone as type specifiers. Short is equivalent to short int and long is equivalent to long int. The following two variable declarations are equivalent:
    [php]
    short cat;
    short int cat;
    [/php]

    Signed and unsigned may also be used in the same way.

    We will now look at the scope of variables.
    There are two types of variables we will look at Global and Local.
    Global variables can be referred from anywhere in the code, even inside functions, whenever it is after its declaration.
    The scope of local variables is limited to the block enclosed in braces where they are declared. If they are declared at the beginning of the body of a function their scope is between its declaration point and the end of that function. This means that if another function existed in addition to main, the local variables declared in main could not be accessed from the other function and the variables from the other function could not be accessed inside main.

    When declaring a regular local variable, its value is automatically undetermined. But you may want a variable to store a value at the same moment that it is declared. In order to do that, you can initialize the variable. There are two ways to do this in C++:
    [php]
    int a = 6;

    OR

    int a (6)
    [/php]



    We are now going to use all this in a program:
    Code:
    #include <iostream>
    using namespace std;
    //you can declare global variables here
    int rabbit = 1;
    int main()
    {
    //you can declare local variables here
    int dog = 3;
    int cat (4);
    cout << dog << endl;
    cout << cat << endl;
    cout << dog + cat << endl;
    dog = rabbit;
    cout << "we have now changed dog to rabbit" << endl;
    cout << dog;
    return 0;
    }
    The result should look like this:
    [php]
    3
    4
    7
    We have now changed dog to rabbit
    1
    [/php]

    Credits:
    cplusplus.com - The C++ Resources Network
    C programming.com - Your Resource for C and C++ Programming
    Me

  7. #7
    P0SEID0N's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    KFC
    Posts
    318
    Reputation
    10
    Thanks
    24
    My Mood
    Lurking
    dont spam, only faggets use smileys.

  8. #8
    Voltage552's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Posts
    252
    Reputation
    10
    Thanks
    135
    Quote Originally Posted by P0SEID0N View Post
    dont spam, only faggets use smileys.
    bo
    [img]https://www.steliar*****m/images/star1.gif[/img][img]https://www.steliar*****m/images/star2.gif[/img][img]https://www.steliar*****m/images/star3.gif[/img][img]https://www.steliar*****m/images/star2.gif[/img][img]https://www.steliar*****m/images/star1.gif[/img]


    Don't expect any more public hacks from me.

    [SA Public]Voltage552 Hook! UNDETECTED - ALL OS

  9. #9
    P0SEID0N's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    KFC
    Posts
    318
    Reputation
    10
    Thanks
    24
    My Mood
    Lurking
    NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO O

Similar Threads

  1. Replies: 3
    Last Post: 04-16-2010, 10:29 PM
  2. Learn how to code C++ || Day 3 - Variables and Date Types
    By P0SEID0N in forum C++/C Programming
    Replies: 5
    Last Post: 04-16-2010, 02:51 AM
  3. Learn how to code C++ || Day 4 - Input and Modifying Variables
    By P0SEID0N in forum CrossFire Hack Coding / Programming / Source Code
    Replies: 0
    Last Post: 04-15-2010, 08:49 PM
  4. Learn how to code C++ || Day 1 - Compiler
    By P0SEID0N in forum CrossFire Hack Coding / Programming / Source Code
    Replies: 14
    Last Post: 04-15-2010, 02:42 AM
  5. Learn how to code C++ || Day 1 - Compiler
    By P0SEID0N in forum C++/C Programming
    Replies: 5
    Last Post: 04-13-2010, 06:21 PM