From a08ebf8d7a52a9e16c6b8c3d34270946f678d399 Mon Sep 17 00:00:00 2001 From: Lucas Rufkahr Date: Mon, 23 Feb 2026 12:19:58 -0600 Subject: [PATCH] Updated cPP.html --- notes/cpp.html | 185 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 154 insertions(+), 31 deletions(-) diff --git a/notes/cpp.html b/notes/cpp.html index 1d5e823..7bfaeed 100644 --- a/notes/cpp.html +++ b/notes/cpp.html @@ -1,38 +1,45 @@ @@ -67,9 +74,9 @@
The main function looks like:
int main() {
-		std::cout << "Hello world" << '\n';
-		return 0;
-	}
+ std::cout << "Hello world" << '\n'; + return 0; +} The int main() { is the declaration of the main function denoting it returns type int. return 0; is the return statement for the function. It is returning the integer 0. This tells the operating system, OK Quit the program safely.

II. Variables

@@ -153,7 +160,123 @@
Constant types are variables identified by const in their type definition. These are not allowed to be modified after they are declared and must be initialized at declaration.

-

Operators

+

III. Operators

+

+ Just like in mathematics, operators let you perform functions on elements. We'll start by viewing arithmetic operators and assignment.
+
+ The assignment operator, denoted by = allows you to assign values to a variable. Assigning a variable with a value of a different type will give you a warning. This can be solved by casting the value being assigned to the same type as your variable: static_cast(var). Assignment also works from right to left. Values on the right of the assignment operator get assigned to the identifier on the left of the assignment operator.
+
+ Arithmetic operators allow you to do operations such as addition, subtraction, multiplication, division, and remainder division.
+
+ When dividing with numbers, it is important to know the type of numbers you are dividing. Division between integers will only return a whole number. For example 5 / 2 = 2. Suppose the 5 was a floating point type then, 5.0 / 2 = 2.5. It is important to know what types you are using when performing division.
+
+ When wanting to perform division and only return the remainder, you can use the modulus operator. For example, 5 / 2 = 2 whereas 5 % 2 = 1. 2 is the quotient and 1 is the remainder.
+

+ There are also ways to quickly perform arithmetic operations using "fast operators". + + + Next we'll approach the relational and logical operators. These allow you to evaluate comparisons between two or more variables.
+
+ Relational Operators + + Logical Operators + + When using multiple operators, it is important to know that operators have a precedence, just like in mathematics.
+
+ Operators with the same precedence are evaluated in the statement from left to right. + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
1stLast
(a)x++, x++++x, --x!* / %+ -< > <= >=== !=&&||=
+

Control Flow

+

I. Decision Branching

+

+ An if statement will execute instructions if the condition evaluates to true. You can remember this as if something is true, then my program will do this. For example: +

int main() {
+	int x = 1;
+	if (x == 1) {
+		std::cout << x << " is equal to 1.\n";
+	}
+	return 0;
+}
+ will execute "1 is equal to 1".
+
+ An if-else statement will execute instructions if the condition is true and execute different instructions when the condition is false.

+
int main() {
+	int x = 1;
+	if (x == 1) {
+		std::cout << x << " is equal to 1.\n";
+	}
+	else {
+		std::cout << x << " is not equal to 1.\n";
+	}
+	return 0;
+}


+ One thing to note about these types of control statements, is that they can be nested to create a decision branch. A branch, like of a tree, splits off into many smaller branches. The more nested if-else statements you have, the more and more branches you add to your decision tree. +

+

II. Loops