How To: Beginner Programming: Part 2 - Primitive Variables and Arithmetic

Title:
How To: Beginner Programming: Part 2 - Primitive Variables and Arithmetic
Description:

In the following series, I aim to demonstrate the basic principles of programming from creating your first "Hello World" application, to developing your own objects.

Visual Studio Express: http://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx

Ascii Table: http://www.bing.com/images/search?q=ascii+table&id=4B026155637477FCF8551CA84681874F29059C98&FORM=IQFRBA#view=detail&id=4B026155637477FCF8551CA84681874F29059C98&selectedIndex=0

[TRANSCRIPT]

Hello, and welcome to How To: Beginner Programming, a multi part guide to your first steps into the world of programming.

In each of the following episodes, I will be demonstrating each of the basic principles of programming from creating your first application, to developing your own objects.

In the previous episode we talked about Hello World as well as setting up the development environment and outputting to the screen.

In this episode I will be explaining what variables are, the types of variables available for use. Also some basic Arithmetic.

Displayed on screen is a list of all the types of primitive variables available for use. As well as an example of how to declare them.

In order to declare a variable you need the type of the variable, the name you wish to give it, which can be whatever you wish but it must be unique to that variable and then the value of the variable, for example:

int i = 1024;

On screen is an example of the upper and lower bounds of each of the types of primitive variables. These types include:

- Byte, which is a 1 byte unsigned integer, so 0 to 255.
- Integer, which is a 4 byte signed integer, -2,147,483,648 to 2,147,483,647.
- Long, which is an 8 byte signed integer,–9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
- Single, which is a 4 byte floating point number. 1.5 x 10^-45 to 3.4 x 10^38
- Double, which is an 8 byte floating point number. 5.0 x 10^-324 to 1.7 x 10^308
- Decimal, which is a 16 byte decimal number. 1.0 x 10^-28 to 7.9 x 10^28
- Boolean, which represents either true or false.
- Char, which represents a single unicode character, for example 'A'.
- String, which represents a sequence of char's.

I will now show you some basic arithmetic calculations which can be applied to these.

All numeric values can be used in arithmetic calculations, for example a decimal of value 10.2 can be added to an int value of 2, returning the decimal value of 12.2.

Oddly, chars can also be added to int values, and vice versa. Each char has a value it is stored in the system with. When added to an int, instead of appending it and returning a string, it adds it with the value of the char. In the case of 'Z' + 2; the value returned would be 92, as 'Z' is stored with a value of 90.
Should the output of this be cast as a char, the value returned would be that of whatever character has the ascii value of 92, so '\'.

Chars can be added to strings to make longer strings, for example the character 's' can be added to the string "Cat" to return the string "Cats".
A string can be anything from a single char to a sequence of chars. So adding 's' to a string of value "" will return a value of "s" which is both a char and a string.

Numeric values can be incremented and decremented with the operator ++ or --. This replaces the value of the variable with that of 1 higher or 1 lower than it currently was.
Variables can also be changed to any value at any point, for example, you can add 10 to the current value of a variable and store it back into that same variable, incrementing it by 10. This can also be written in shorthand as variablename++10;.

So! That is part two of How To: Beginner Programming. Further parts will be released shortly, but, again I will leave a gap in between to allow you to ask any questions you may have, and I will answer them at the start of the following part.

Thank you very much for watching. Again, please leave all questions in the comment section below. See you next time.

more » « less
Video Language:
English, British
Duration:
10:43
http://www.youtube.com/watch?v=-st2Nz5kGsk
Format: Youtube
Primary
Original
Added   by None
Format: Youtube
Primary
Original
This video is part of Amara Public.

Subtitles download

Completed subtitles (1)