From 332683b00755d95d15e7db1def9d46a1e7d5012a Mon Sep 17 00:00:00 2001 From: Lucas Rufkahr Date: Mon, 2 Mar 2026 14:04:48 -0600 Subject: [PATCH] update hugo --- content/cpp/.functions.md.swp | Bin 0 -> 12288 bytes content/cpp/functions.md | 139 ---------------------------------- 2 files changed, 139 deletions(-) create mode 100644 content/cpp/.functions.md.swp diff --git a/content/cpp/.functions.md.swp b/content/cpp/.functions.md.swp new file mode 100644 index 0000000000000000000000000000000000000000..2284be31c9ae4862a13a1d53a3fed69b6d292329 GIT binary patch literal 12288 zcmeI&O-|cD0EXd#H7E!!U_io)$gy$wjl`CU1q%wHrIeqEGfqs5?T*Jlqzd+2peNuC zJwz|iGxQ2w^s@<4g_LH{XY-UQC<^gOG3m& zAah-W1KHQ*?bnWh%3`IRxY3h(m?+aob?>FIxBoBbeu#{FtvY#RlpCapQHgPbEOWym z2~3nGdE>JC(klFp1z2G00)+{kjp=sNU-rtmiwpDC+-!U7WjKKaSbzmsfCX591z3Ou zSm6B@FxiB-!{bkme!|q~Jn`&2y5xxkSbzmsfCX591z3OuSbzmsfCX6K9Tt$-W3ShQ zz?Oft|Nr#=|1Yk8!!P&=5AXx-;XB;GHC#bCSHm~RAcX`jA%+25Km>j0K?n-E5I_ec zoWmKM!U=qZWB39`@EJbAA++HD_TeM!0S^{n0Ty5Z7GMDuU;!3j0Ty5Z7I-5C7A-tT zyB(=7zrZBRXYS_|4YpdTYgZytS6++0`@r17tpG=>Px# literal 0 HcmV?d00001 diff --git a/content/cpp/functions.md b/content/cpp/functions.md index 246bd15..c36b05d 100644 --- a/content/cpp/functions.md +++ b/content/cpp/functions.md @@ -8,142 +8,3 @@ tags = 'cpp' chapterno = 3 +++ -## I. Introduction - -A C++ program generally consists of preprocessor directives and the main function. - -A preprocessor directive tells the C++ preprocessor what to do before compiling. You can use this to include files, create macros, and determine compiling based on conditions. For example, include a file using `#include` This will include the iostream file from the C++ standard library. - -The main function looks like: - -```c++ -int main() { - 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 - -A variable lets you allocate some memory in the computer and use it to store values. You can also recall the values for later. Variables contain a memory address and an identifier. An identifier can be \*almost\* anything you wish it to be. - -Variables naming rules: - -- Cannot start with a number. -- Can only contain alphanumeric characters and underscores. -- Cannot contain any reserved keywords [(see here)](https://en.cppreference.com/w/cpp/keyword.html). -- If starting with an underscore, it can only start with one. - -All variables have denoted types and they refer to what kind of variable it is. All variables also have a bit size and this denotes the range of values that can be stored. - -Variable types: - -- Integers: - - short int: - - Size: 2 bytes. - - Range: -32,768 to 32,767 - - int: - - Size: 4 bytes. - - Range: -2 billion to 2 billion - - short: - - Size: 8 bytes. - -- Floats: - - float: - - Size: 4 bytes. - - 6 significant figures. - - double: - - Size: 8 bytes. - - 15 significant figures. - - long double: - - Size: 16 bytes. - - 19 significant figures. - -- Character: - - char - - Stores an integer value representative of an "ASCII" character. - - Size: 1 byte. - -- String: - - string - - Stores an indexable array of characters. - - Variable creation: `std::string identifier = "string literal";` - -- Boolean: - - bool - - Stores an integer value of 0 or 1 representative of false or true respectively. - - Size: 1 byte - - -Variables are always declared before they are initialized. This means you must determine the type and the identifier before you store any values into it. - -```c++ -int main() { - int a; // Declaration - a = 1; // Initialization - int b = 2; // Declaration then initialization -} -``` - -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. - -## 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. - -- \+ Addition -- \- Subtraction -- \* Multiplication -- / Division -- % Modulus - -There are also ways to quickly perform arithmetic operations using "fast operators". - -- Post increment/decrement: - - This will return the current value and then perform the operation. - - `x++` - - `x--` -- Pre increment/decrement: - - This will perform the operation, then return the current value. - - `++x` - - `--x` - -The following is short for `x = x (operation) y`: -- `x += y` -- `x -= y` -- `x *= y` -- `x /= y` -- `x %= y` - -Next we'll approach the relational and logical operators. These allow you to evaluate comparisons between two or more variables. - -Relational Operators: -- Less than: < -- Greater than: > -- Less than or equal to: <= -- Greater than or equal to: >= -- Is equal to: == -- Is not equal to: != - -Logical Operators: -- AND: && -- OR: || -- NOT: ! - -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. -|Precedence|Operator(s)| -|----------|-----------| -|1 |Parenthesis| -|2 |x++, x-- | -|3 |++x, --x | -|4 |! | -|5 |* / % | -|6 |+ - | -|7 |< > <= >= | -|8 |== != | -|9 |&& | -|10 |\|\| | -|11 |= | -