INTRODUCTION TO PROGRAMMING
I am collating my study notes as part of my education into Computer Programming. In an attempt to increase and improce my own learning, and to help others also (learn by teaching) I will be sharing my notes, as neatly presented as possible, for others to follow along with if they so wish. This is Lesson 3's notes.
EARLIER LESSONS
INTRODUCTION TO COMPUTER PROGRAMMING – STUDY NOTES
LESSON 3
OPERATORS
LINK: Operators
Operators allow you to operate on an element of the program.
- Assignment
=
This means to apply the value of. For example x = y means to apply the value of x to y. It is not the same meaning as standard mathematics where it means equal to.
- Arithmetic Operators
+
Addition
-
Subtraction
*
Multiplication
/
Division
%
Modulo
- Modulo = remainder of a division operation.
Example 143 / 3 = 47.66 (standard division) but if you take only the whole numbers, then the modulo of that operation is 143 / 3 = 47, WITH a remainder of 2. In other words, 47 * 3 = 141 and the difference between 143 and 141 is 2 (This is the modulo, or the remainder). There is a need for such an operator within programming languages.
- Compound Operators
+=
: x+=y is the same as saying x=x+y
-+
: x-=y is the same as saying x=x-y
*+
: x=y is the same as saying x=xy
/=
: x/=y is the same as saying x=x/y
%=
: x%=y is the same as saying x=x%y
This allows for a slightly shorter way of writing out these operators.
- Unary Operators
++
:X++
is the same as sayingx=x+1
(used a lot in loops)
--
:X--
is the same as sayingx=x-1
(used a lot in loops)
!
: Means NOT.
Example :x=true
, then!x
would then be false (ie - NOT true)
- Prefix Operator vs Suffix Operator
LINK: Increment and Decrement Operators
When the ++ or -- is set as a prefix as opposed to a suffix like earlier described, then the value of the variable that it relates to is handled differently. The variable is increased FIRST then assigned to the new variable.
Prefix Example:
x = 3
y = ++x
In this example x is assigned (=) the value of 3, and then because of the PREFIX in the second line, x is increased by 1 to 4 (++x) BEFORE y is assigned that value. Now both x and y have the value of 4.
The suffix example would create a different answer.
Suffix Example
x = 3
y = x++
In this example x is assigned (=) the value of 3, and then because of the SUFFIX in the second line, x is increased by 1 to 4 (x++) AFTER y is assigned that value. So y is assigned the value of x which is 3, THEN x is increased by 1 to 4.
This seemingly minor but significant difference can lead to logical errors in your program if you apply the wrong use of suffix/prefix.
Suffix = value is assigned first before it is increased.
Prefix = value is increased first before it is assigned.
- Relational/Comparison Operator
Used to compare 2 values.
Will always evaluate to a Boolean value (TRUE or FALSE).
==
: equal to
!=
: not equal to
>
: greater than
<
: less than
>=
: greater than or equal to
<=
: less than or equal to
- Logical Operator
Used to tell the computer to do an operation when certain conditions or mix of conditions are met. Such as condition 1 AND condition 2; condition 1 OR condition 2. Also the NOT operator.
!
: NOT :
&&
: AND : True only when both conditions are true.
||
: OR : True if one or the other is true.
- Operator Precedence
There is an order to which operators are evaluated. There is an order of importance.
All the languages use the same precedence.
LINK: C++ Example
LINK: JavaScript Example
FURTHER DATA
cpp.sh - C++ shell website
Scratchpad - Shift + F4 on Firefox - Javascript shell
Dev C++ - A free, portable, fast and simple C/C++ IDE
Code::Blocks - A free C, C++ and Fortran IDE
Ideone - an online compiler and debugging tool which allows youto compile source code and execute it online in more than 60 programming languages.
My Posts
Introduction From a Newbie Programmer.
Introduction to Computer Programming - part 1 (Lesson 1)
Introduction to Computer Programming - part 2 (Lesson 2)
Images from unsplash.com.
I welcome new followers, and thank you for your upvotes and comments.
Congratulations! This post has been upvoted from the communal account, @minnowsupport, by humate from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews/crimsonclad, and netuoso. The goal is to help Steemit grow by supporting Minnows and creating a social network. Please find us in the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.
If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP. Be sure to leave at least 50SP undelegated on your account.
This post has received a 0.03 % upvote from @drotto thanks to: @banjo.
Congratulations @humate! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Award for the number of upvotes
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP