Results 1 to 6 of 6
  1. #1
    Bot Bot's Avatar
    Join Date
    Aug 2011
    Posts
    2,671
    Points
    7,720
         User Info     Contact     Gamer ID
    Join Date
    Aug 2011
    Posts
    2,671
    Points
    7,720

    Post [C++] TUT - Lesson 2 - Data Types & Variables

    Ok so now we have learned to code C++ and made our first Hello World app we can move on.

    Let's move on to variables and data types.

    Variables
    Variables are letters or words or whatever else you define them as within your code (we shall get onto declaring variables in a minute). The word you use for the variable is called an indentifier. So for example you could have some code such as this
    Code:
    a = 9;
    b = 5;
    a = a + 1;
    result = a - b;
    So you have 2 variables in this code a and b. You assign the value of 9 to a, you assign 5 to b, then a increases by 1. The result (another identifier) is then (a+1)-(b) = (9+1)-(5) = 10-5 = 5. So the result is assigned 5.

    Do remember though:
    - identifiers (a, b and result) cannot be completely anything - you cannot use reserved words

    - C++ is case sensetive so if you use an identifier such as 'a' then do not then start using 'A' as the program deals with cases as if they were sepearte letters/words.

    -------------------------------------------------------------------------------------------------
    Data Types
    To declare our variable we need to decide what data type it is, here is a table to help you:

    Name - Description- Size* - Range*

    char - Character or small integer. - 1byte - signed: -128 to 127 unsigned: 0 to 255
    short int (short) - Short Integer. - 2bytes - signed: -32768 to 32767 unsigned: 0 to 65535
    int - Integer. - 4bytes - signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295
    long int (long) - Long integer. - 4bytes - signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295
    bool - Boolean value. It can take one of two values: true or false. - 1byte - true or false
    float - Floating point number. - 4bytes - +/- 3.4e +/- 38 (~7 digits)
    double - Double precision floating point number. - 8bytes - +/- 1.7e +/- 308 (~15 digits)
    long double - Long double precision floating point number. - 8bytes - +/- 1.7e +/- 308 (~15 digits)
    wchar_t - Wide character. - 2 or 4 bytes - 1 wide character

    * The values of the columns Size and Range depend on the system the program is compiled for.

    The memory in our computer is organised in bytes. A byte is the minimum amount of memory that we can
    manage in C++, it can store a relatively small amount of data: a single character or a small integer
    (generally an integer between 0 and 255). However we can use more bytes and store more complex/longer/bigger numbers.


    Previous Lesson: http://www.codeleakers.com/showthrea...n-1-The-Basics
    Next Lesson: http://www.codeleakers.com/showthrea...ring-Variables

    0 Not allowed! Not allowed!
    Last edited by Bot; 09-23-2011 at 05:50 AM. Reason: Added Lesson Links








  2. #2
    V.XVII.XIV Synix's Avatar
    Join Date
    Aug 2011
    Posts
    2,655
    Points
    2,314
         User Info     Contact     Gamer ID
    Join Date
    Aug 2011
    Posts
    2,655
    Points
    2,314
    Gamer IDs

    PSN ID: I-Synix-I

    Contact info:

    Kik Username: SynixMods

    Default

    Could you send me the link to the first tutorial :3

    0 Not allowed! Not allowed!
    Last edited by Bot; 09-23-2011 at 05:47 AM.
    DM<3
    Instagram: @Synix_
    PSN: SKDM-
    Kik: SynixMods

  3. #3
    Bot Bot's Avatar
    Join Date
    Aug 2011
    Posts
    2,671
    Points
    7,720
         User Info     Contact     Gamer ID
    Join Date
    Aug 2011
    Posts
    2,671
    Points
    7,720

    Default

    Quote Originally Posted by sim0n-m0dz View Post
    Could you send me the link to the first tutorial :3
    http://www.codeleakers.com/showthrea...-Prerequisites

    Quotes removed from previous post.

    0 Not allowed! Not allowed!
    Last edited by Bot; 09-23-2011 at 05:47 AM.








  4. #4
    Robot Universe Owner
    Creator of DarkFrost
    demon450's Avatar
    Join Date
    Apr 2010
    Location
    New York
    Posts
    2,717
    Points
    6,208
         User Info     Contact     Gamer ID
    Join Date
    Apr 2010
    Location
    New York
    Posts
    2,717
    Points
    6,208
    Gamer IDs

    Gamertag: Medius450 PSN ID: Medius1337

    Contact info:

    Youtube Channel: http://www.youtube.com/user/Roceso1337

    Default

    since when is bool a type? is that just in C++? i mainly work in C :P

    0 Not allowed! Not allowed!
    Check out Darkfrost
    Check out Robot Universe






  5. #5
    Bot Bot's Avatar
    Join Date
    Aug 2011
    Posts
    2,671
    Points
    7,720
         User Info     Contact     Gamer ID
    Join Date
    Aug 2011
    Posts
    2,671
    Points
    7,720

    Default

    Quote Originally Posted by demon450 View Post
    since when is bool a type? is that just in C++? i mainly work in C :P
    Yeah, there is not a boolean data type in C.

    0 Not allowed! Not allowed!








  6. #6
    Nooblet angrymasteryoda's Avatar
    Join Date
    Mar 2010
    Posts
    6
    Points
    9
         User Info     Contact     Gamer ID
    Join Date
    Mar 2010
    Posts
    6
    Points
    9
    Gamer IDs

    Steam ID: angrymasteryoda

    Default

    by the way long vars are the same as there type ie int = long int rarely need to use long's unless specifically asked too

    0 Not allowed! Not allowed!
    I is here

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -10. The time now is 12:34 PM.
Powered by vBulletin®
Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.