From 3722b03e69afad3ec097be8b568ec61930b88e6d Mon Sep 17 00:00:00 2001 From: <> Date: Fri, 3 May 2024 16:09:42 +0000 Subject: [PATCH] Deployed 2fc2852 with MkDocs version: 1.6.0 --- 404.html | 2 +- arrays/index.html | 2 +- basics/index.html | 2 +- ccc/index.html | 2 +- conditionals/index.html | 2 +- functions/index.html | 2 +- get-started/index.html | 2 +- index.html | 2 +- loops/index.html | 2 +- pointers/index.html | 2 +- sitemap.xml.gz | Bin 127 -> 127 bytes 11 files changed, 10 insertions(+), 10 deletions(-) diff --git a/404.html b/404.html index babd07f..c71ff7a 100644 --- a/404.html +++ b/404.html @@ -1 +1 @@ - Learn C++

404 - Not found

\ No newline at end of file + Learn C++

404 - Not found

\ No newline at end of file diff --git a/arrays/index.html b/arrays/index.html index 7b46333..cff6574 100644 --- a/arrays/index.html +++ b/arrays/index.html @@ -7,7 +7,7 @@ .gdesc-inner { font-size: 0.75rem; } body[data-md-color-scheme="slate"] .gdesc-inner { background: var(--md-default-bg-color);} body[data-md-color-scheme="slate"] .gslide-title { color: var(--md-default-fg-color);} - body[data-md-color-scheme="slate"] .gslide-desc { color: var(--md-default-fg-color);}
Skip to content

C++ Arrays

Basics

Arrays are commonly used to store multiple values. It's one of the basic data structures. We can use it to model a list/array/collection of items. Say, an array of cellphone numbers, an array of first names, etc.

To declare an array in C++, we need to specify 3 things, using the square bracket notation.

  • Data Type
  • Size
  • Name of the array

For example,

float scores[5];
+    body[data-md-color-scheme="slate"] .gslide-desc { color: var(--md-default-fg-color);}       

C++ Arrays

Basics

Arrays are commonly used to store multiple values. It's one of the basic data structures. We can use it to model a list/array/collection of items. Say, an array of cellphone numbers, an array of first names, etc.

To declare an array in C++, we need to specify 3 things, using the square bracket notation.

  • Data Type
  • Size
  • Name of the array

For example,

float scores[5];
 

To initialize values in the array during declaration, we can use the curly bracket notation.

float scores[5] = {90.5, 88, 75.5, 89, 95.5}
 

Or simply omitting the size, the compiler is smart enough to count the number of values to be inserted.

float scores[] = {90.5, 88, 75.5, 89, 95.5}
 

We can access each of the values in an array by its index, using the square bracket notation. C++ is zero-indexed, meaning the first value in the array has an index of 0.

For example, to retrieve the second scores from the scores array, we can simply

cout << scores[1] << endl;
diff --git a/basics/index.html b/basics/index.html
index 7aaa2e9..acf2d57 100644
--- a/basics/index.html
+++ b/basics/index.html
@@ -7,7 +7,7 @@
     .gdesc-inner { font-size: 0.75rem; }
     body[data-md-color-scheme="slate"] .gdesc-inner { background: var(--md-default-bg-color);}
     body[data-md-color-scheme="slate"] .gslide-title { color: var(--md-default-fg-color);}
-    body[data-md-color-scheme="slate"] .gslide-desc { color: var(--md-default-fg-color);}       

Basics of C++

File extension

We use .cpp for C++ source codes.

Execution

C++ is a compiled language, meaning that it will be translated into machine codes that can be understood directly by the system. Hence, in order to execute a C++ program, we need to compile then run the executable.

Let's use the Hello, World! program as an example.

hello-world.cpp
1
+    body[data-md-color-scheme="slate"] .gslide-desc { color: var(--md-default-fg-color);}       

Basics of C++

File extension

We use .cpp for C++ source codes.

Execution

C++ is a compiled language, meaning that it will be translated into machine codes that can be understood directly by the system. Hence, in order to execute a C++ program, we need to compile then run the executable.

Let's use the Hello, World! program as an example.

hello-world.cpp
1
 2
 3
 4
diff --git a/ccc/index.html b/ccc/index.html
index 7eeab73..d32936c 100644
--- a/ccc/index.html
+++ b/ccc/index.html
@@ -7,7 +7,7 @@
     .gdesc-inner { font-size: 0.75rem; }
     body[data-md-color-scheme="slate"] .gdesc-inner { background: var(--md-default-bg-color);}
     body[data-md-color-scheme="slate"] .gslide-title { color: var(--md-default-fg-color);}
-    body[data-md-color-scheme="slate"] .gslide-desc { color: var(--md-default-fg-color);}       

CCC

The Canadian Computing Competition (CCC) is a fun challenge for students with an interest in programming. Designed to be both accessible to students with some programming experience and to challenge the keenest programmers at the secondary-school level, the CCC helps students build confidence and grow their ability to design, understand and implement algorithms.

See more from official site. Let's give it a try

J1

With what we have learned so far, we should be able to solve most J1 and J2 problems.

For example, let's take a look at J1 from 2020's contest.

Sample Solution for 2020-J1
2020-J1
 1
+    body[data-md-color-scheme="slate"] .gslide-desc { color: var(--md-default-fg-color);}       

CCC

The Canadian Computing Competition (CCC) is a fun challenge for students with an interest in programming. Designed to be both accessible to students with some programming experience and to challenge the keenest programmers at the secondary-school level, the CCC helps students build confidence and grow their ability to design, understand and implement algorithms.

See more from official site. Let's give it a try

J1

With what we have learned so far, we should be able to solve most J1 and J2 problems.

For example, let's take a look at J1 from 2020's contest.

Sample Solution for 2020-J1
2020-J1
 1
  2
  3
  4
diff --git a/conditionals/index.html b/conditionals/index.html
index 4d9fc9f..3472b6c 100644
--- a/conditionals/index.html
+++ b/conditionals/index.html
@@ -7,7 +7,7 @@
     .gdesc-inner { font-size: 0.75rem; }
     body[data-md-color-scheme="slate"] .gdesc-inner { background: var(--md-default-bg-color);}
     body[data-md-color-scheme="slate"] .gslide-title { color: var(--md-default-fg-color);}
-    body[data-md-color-scheme="slate"] .gslide-desc { color: var(--md-default-fg-color);}       

Conditional statements in C++

C++ has if-else and switch to determine whether statements would execute based on a given condition.

if statement

Use if to specify a block of code to be executed, if a specified condition is true. The syntax is as follows.

if (condition) {
+    body[data-md-color-scheme="slate"] .gslide-desc { color: var(--md-default-fg-color);}       

Conditional statements in C++

C++ has if-else and switch to determine whether statements would execute based on a given condition.

if statement

Use if to specify a block of code to be executed, if a specified condition is true. The syntax is as follows.

if (condition) {
     // statements
 }
 

For example,

test-if.cpp
 1
diff --git a/functions/index.html b/functions/index.html
index 5cc41a6..48a7e70 100644
--- a/functions/index.html
+++ b/functions/index.html
@@ -7,7 +7,7 @@
     .gdesc-inner { font-size: 0.75rem; }
     body[data-md-color-scheme="slate"] .gdesc-inner { background: var(--md-default-bg-color);}
     body[data-md-color-scheme="slate"] .gslide-title { color: var(--md-default-fg-color);}
-    body[data-md-color-scheme="slate"] .gslide-desc { color: var(--md-default-fg-color);}       

C++ Functions

A function is a block of code that runs when it is called. It can take data as input (known as parameters) and generate output (know as return value).

Functions are used to create reusable and modular codes.

Declaration, Definition, and Execution

A C++ function consists of two parts:

  • Declaration: the function name, parameters if any, and return type
  • Definition: the body of function

To execute a function, invoke the name with () and provide parameters if required.

For example

func-say-hi.cpp
 1
+    body[data-md-color-scheme="slate"] .gslide-desc { color: var(--md-default-fg-color);}       

C++ Functions

A function is a block of code that runs when it is called. It can take data as input (known as parameters) and generate output (know as return value).

Functions are used to create reusable and modular codes.

Declaration, Definition, and Execution

A C++ function consists of two parts:

  • Declaration: the function name, parameters if any, and return type
  • Definition: the body of function

To execute a function, invoke the name with () and provide parameters if required.

For example

func-say-hi.cpp
 1
  2
  3
  4
diff --git a/get-started/index.html b/get-started/index.html
index 5726cdc..13bb245 100644
--- a/get-started/index.html
+++ b/get-started/index.html
@@ -7,5 +7,5 @@
     .gdesc-inner { font-size: 0.75rem; }
     body[data-md-color-scheme="slate"] .gdesc-inner { background: var(--md-default-bg-color);}
     body[data-md-color-scheme="slate"] .gslide-title { color: var(--md-default-fg-color);}
-    body[data-md-color-scheme="slate"] .gslide-desc { color: var(--md-default-fg-color);}       

Getting Started

To start using C++, we need two things:

  • A compiler
  • A text editor

Compiler

For Windows users, we can use the WinLibs standalone build of GCC and MinGW-w64.

Let's get the Universal C Runtime version from WinLibs. As of September 2022, the latest version is GCC 12.2.0 + LLVM/Clang/LLD/LLDB 14.0.6 + MinGW-w64 10.0.0 (UCRT) - release 2.

Download the zip file and extract to a preferable location. Then add the path of that preferable location in the PATH environment variable.

To verify the installation of compiler, open a new terminal and run

g++ -v
+    body[data-md-color-scheme="slate"] .gslide-desc { color: var(--md-default-fg-color);}       

Getting Started

To start using C++, we need two things:

  • A compiler
  • A text editor

Compiler

For Windows users, we can use the WinLibs standalone build of GCC and MinGW-w64.

Let's get the Universal C Runtime version from WinLibs. As of September 2022, the latest version is GCC 12.2.0 + LLVM/Clang/LLD/LLDB 14.0.6 + MinGW-w64 10.0.0 (UCRT) - release 2.

Download the zip file and extract to a preferable location. Then add the path of that preferable location in the PATH environment variable.

To verify the installation of compiler, open a new terminal and run

g++ -v
 

If the version displays, we are good to go.

Text Editor

We recommend using Visual Studio Code as the coding interface. Also make sure we install the C/C++ extension.

\ No newline at end of file diff --git a/index.html b/index.html index 36a4922..aff67b0 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@ .gdesc-inner { font-size: 0.75rem; } body[data-md-color-scheme="slate"] .gdesc-inner { background: var(--md-default-bg-color);} body[data-md-color-scheme="slate"] .gslide-title { color: var(--md-default-fg-color);} - body[data-md-color-scheme="slate"] .gslide-desc { color: var(--md-default-fg-color);}

Logo

Hello, World!

This is a C++ program, which displays the famous "Hello, World!" in the terminal.

hello-world.cpp
1
+    body[data-md-color-scheme="slate"] .gslide-desc { color: var(--md-default-fg-color);}       

Logo

Hello, World!

This is a C++ program, which displays the famous "Hello, World!" in the terminal.

hello-world.cpp
1
 2
 3
 4
diff --git a/loops/index.html b/loops/index.html
index f9344f1..16d49cf 100644
--- a/loops/index.html
+++ b/loops/index.html
@@ -7,7 +7,7 @@
     .gdesc-inner { font-size: 0.75rem; }
     body[data-md-color-scheme="slate"] .gdesc-inner { background: var(--md-default-bg-color);}
     body[data-md-color-scheme="slate"] .gslide-title { color: var(--md-default-fg-color);}
-    body[data-md-color-scheme="slate"] .gslide-desc { color: var(--md-default-fg-color);}       

Loops in C++

Loops are indented to repeat a block of codes as long as a condition is met. There are different forms of loops in C++.

while statement

The while loop repeats a block of code as long as a specified condition is true. The syntax is as follows.

while (condition){
+    body[data-md-color-scheme="slate"] .gslide-desc { color: var(--md-default-fg-color);}       

Loops in C++

Loops are indented to repeat a block of codes as long as a condition is met. There are different forms of loops in C++.

while statement

The while loop repeats a block of code as long as a specified condition is true. The syntax is as follows.

while (condition){
     // code block to repeat
 }
 

For example,

print-till-ten-with-while.cpp
 1
diff --git a/pointers/index.html b/pointers/index.html
index 5e74c3f..b554b08 100644
--- a/pointers/index.html
+++ b/pointers/index.html
@@ -7,7 +7,7 @@
     .gdesc-inner { font-size: 0.75rem; }
     body[data-md-color-scheme="slate"] .gdesc-inner { background: var(--md-default-bg-color);}
     body[data-md-color-scheme="slate"] .gslide-title { color: var(--md-default-fg-color);}
-    body[data-md-color-scheme="slate"] .gslide-desc { color: var(--md-default-fg-color);}       

C++ Pointers

Basics

When a variable is created, a memory address is assigned to that variable. And When we assign some value to the variable, the value is stored in that memory address.

We can use & operator to get the memory address of a variable.

show-mem-addr.cpp
 1
+    body[data-md-color-scheme="slate"] .gslide-desc { color: var(--md-default-fg-color);}       

C++ Pointers

Basics

When a variable is created, a memory address is assigned to that variable. And When we assign some value to the variable, the value is stored in that memory address.

We can use & operator to get the memory address of a variable.

show-mem-addr.cpp
 1
  2
  3
  4
diff --git a/sitemap.xml.gz b/sitemap.xml.gz
index 84363ddf876d645f59c957e44c9331dd80f0839e..d90497405810b7e5829e7b1fe872789f5e401408 100644
GIT binary patch
delta 13
Ucmb=gXP58h;9$@+naExN02e3&EdT%j

delta 13
Ucmb=gXP58h;9z*HH<7&p02;Cb;Q#;t