diff --git a/README.md b/README.md index 5e5d985..654098e 100644 --- a/README.md +++ b/README.md @@ -50,8 +50,8 @@ https://mybinder.org/v2/gh/mmoelle1/OospCpp/binder?urlpath=git-pull%3Frepo%3Dhtt [pages-lecture1]: https://mmoelle1.github.io/OospCpp/_static/lecture1.slides.html [pages-lecture2]: https://mmoelle1.github.io/OospCpp/_static/lecture2.slides.html -[pages-lecture3]: https://mmoelle1.github.io/OospCpp/_static/lecture3.slides.html -[pages-lecture4]: https://mmoelle1.github.io/OospCpp/_static/lecture4.slides.html +[pages-lecture3]: https://mmoelle1.github.io/OospCpp/notebooks/static/lecture3.slides.html +[pages-lecture4]: https://mmoelle1.github.io/OospCpp/notebooks/static/lecture4.slides.html [pages-lecture5]: https://mmoelle1.github.io/OospCpp/_static/lecture5.slides.html [pages-lecture6]: https://mmoelle1.github.io/OospCpp/_static/lecture6.slides.html [pages-lecture7]: https://mmoelle1.github.io/OospCpp/_static/lecture7.slides.html diff --git a/notebooks/static/.DS_Store b/notebooks/static/.DS_Store new file mode 100644 index 0000000..2036d14 Binary files /dev/null and b/notebooks/static/.DS_Store differ diff --git a/notebooks/static/lecture3.slides.html b/notebooks/static/lecture3.slides.html new file mode 100644 index 0000000..0024e32 --- /dev/null +++ b/notebooks/static/lecture3.slides.html @@ -0,0 +1,16923 @@ + + + + + + + + + +lecture3 slides + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + + + + + + + + + + diff --git a/notebooks/static/lecture4.slides.html b/notebooks/static/lecture4.slides.html new file mode 100644 index 0000000..c6e788c --- /dev/null +++ b/notebooks/static/lecture4.slides.html @@ -0,0 +1,16670 @@ + + + + + + + + + + +lecture4 slides + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + + + + + + + + + + diff --git a/notebooks/static/plots/.DS_Store b/notebooks/static/plots/.DS_Store new file mode 100644 index 0000000..e40864b Binary files /dev/null and b/notebooks/static/plots/.DS_Store differ diff --git a/notebooks/static/plots/OOPs-Concepts.jpg b/notebooks/static/plots/OOPs-Concepts.jpg new file mode 100644 index 0000000..df36246 Binary files /dev/null and b/notebooks/static/plots/OOPs-Concepts.jpg differ diff --git a/notebooks/static/plots/address-of.png b/notebooks/static/plots/address-of.png new file mode 100644 index 0000000..91ad51b Binary files /dev/null and b/notebooks/static/plots/address-of.png differ diff --git a/notebooks/static/plots/class_lego.png b/notebooks/static/plots/class_lego.png new file mode 100644 index 0000000..fed69c5 Binary files /dev/null and b/notebooks/static/plots/class_lego.png differ diff --git a/notebooks/static/plots/cppexample1.png b/notebooks/static/plots/cppexample1.png new file mode 100644 index 0000000..fb77aba Binary files /dev/null and b/notebooks/static/plots/cppexample1.png differ diff --git a/notebooks/static/plots/cppexample2.png b/notebooks/static/plots/cppexample2.png new file mode 100644 index 0000000..8922b0d Binary files /dev/null and b/notebooks/static/plots/cppexample2.png differ diff --git a/notebooks/static/plots/cppexample3.png b/notebooks/static/plots/cppexample3.png new file mode 100644 index 0000000..199e445 Binary files /dev/null and b/notebooks/static/plots/cppexample3.png differ diff --git a/notebooks/static/plots/cppprocon1.png b/notebooks/static/plots/cppprocon1.png new file mode 100644 index 0000000..b8b36ba Binary files /dev/null and b/notebooks/static/plots/cppprocon1.png differ diff --git a/notebooks/static/plots/doublepointer.png b/notebooks/static/plots/doublepointer.png new file mode 100644 index 0000000..1333cdf Binary files /dev/null and b/notebooks/static/plots/doublepointer.png differ diff --git a/notebooks/static/plots/dynamicarray.png b/notebooks/static/plots/dynamicarray.png new file mode 100644 index 0000000..ecad3c7 Binary files /dev/null and b/notebooks/static/plots/dynamicarray.png differ diff --git a/notebooks/static/plots/flashback.png b/notebooks/static/plots/flashback.png new file mode 100644 index 0000000..9dff5df Binary files /dev/null and b/notebooks/static/plots/flashback.png differ diff --git a/notebooks/static/plots/historycpp.png b/notebooks/static/plots/historycpp.png new file mode 100644 index 0000000..3446d63 Binary files /dev/null and b/notebooks/static/plots/historycpp.png differ diff --git a/notebooks/static/plots/lecture1-4.ipynb b/notebooks/static/plots/lecture1-4.ipynb new file mode 100644 index 0000000..d289f2b --- /dev/null +++ b/notebooks/static/plots/lecture1-4.ipynb @@ -0,0 +1 @@ +{"metadata":{"celltoolbar":"Slideshow","kernelspec":{"name":"xcpp17","display_name":"C++17","language":"C++17"},"language_info":{"codemirror_mode":"text/x-c++src","file_extension":".cpp","mimetype":"text/x-c++src","name":"c++","version":"17"},"rise":{"autolaunch":true,"enable_chalkboard":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Object-oriented scientific programming with C++\n\nMatthias Möller, Jonas Thies (Numerical Analysis, DIAM)\n\nLecture 1","metadata":{"editable":false,"raw_mimetype":"","slideshow":{"slide_type":"slide"},"tags":[]}},{"cell_type":"markdown","source":"## What's this course about","metadata":{"editable":false,"slideshow":{"slide_type":"slide"},"tags":[]}},{"cell_type":"markdown","source":"### Object oriented programming\n\nLearn the **design principles** of OOP (not restricted to C++)","metadata":{"slideshow":{"slide_type":"subslide"},"tags":[]}},{"cell_type":"markdown","source":"### Matlab example\n\n```Matlab\nA = [1 2; 3 4]\nsize(A)\n```\n\nHere, the `size` **functions** is applied to the matrix `A` and determines its size from outside. That means the function `size` must be able to deduce the matrix size. In other words, the matrix size is publicly visible.","metadata":{"editable":false,"slideshow":{"slide_type":"subslide"},"tags":[]}},{"cell_type":"markdown","source":"### Python example\n\n```python\nA = numpy.matrix([[1, 2], [3, 4]])\nA.shape\n```\n\nHere, the matrix `A` provides a _member function_ to determine its size from inside.","metadata":{"editable":false,"slideshow":{"slide_type":"subslide"},"tags":[]}},{"cell_type":"markdown","source":"### Header files\n\nAt the beginning of each C++ code you include some **header files**, for instance the one for input and output streams","metadata":{"editable":false,"slideshow":{"slide_type":"slide"},"tags":[]}},{"cell_type":"code","source":"#include ","metadata":{"slideshow":{"slide_type":"fragment"},"tags":[]},"execution_count":2,"outputs":[]},{"cell_type":"markdown","source":"Now, we can write our first C++ instruction","metadata":{"editable":false,"slideshow":{"slide_type":"fragment"},"tags":[]}},{"cell_type":"markdown","source":"std::cout << \"Hello World!\\n\";","metadata":{"slideshow":{"slide_type":"fragment"},"tags":[]}},{"cell_type":"markdown","source":"\n

What's this course about?

\n

1. Object oriented programming

\n

Learn the design principles of OOP (not restricted to C++)

\n
vs.
\n","metadata":{"slideshow":{"slide_type":"subslide"}}},{"cell_type":"markdown","source":"\n

What's this course about?

\n

2. Scientific programming

\n

Help you to solve problems from your BSc, MSc, PhD, ... project

\nThink big!\n \n Think fail-safe!\n \nThink future-proof!\n \n","metadata":{}},{"cell_type":"markdown","source":"\n

Otherwise...

\n
","metadata":{"tags":[]}},{"cell_type":"markdown","source":"
\n

A talk from Bjarne Stroustrup about why he created C++

","metadata":{"tags":[]}},{"cell_type":"markdown","source":"

Course information

\n\n

To be added...

","metadata":{}},{"cell_type":"markdown","source":"

About the unit tests

\n","metadata":{}},{"cell_type":"markdown","source":"

Fraud

\n","metadata":{"tags":[]}},{"cell_type":"markdown","source":"

After all formalities ...

\n","metadata":{}},{"cell_type":"markdown","source":"\n\n\n\n\n\n
Programming Languages
\n
Introduction to Computer Programming
\n","metadata":{}},{"cell_type":"markdown","source":"

Programming languages

\n\n","metadata":{"tags":[]}},{"cell_type":"markdown","source":"

Pros and Cons of interpreted languages

\n
","metadata":{"tags":[]}},{"cell_type":"markdown","source":"

Pros and Cons of compiled languages

\n
","metadata":{"tags":[]}},{"cell_type":"markdown","source":"

Example of a compiled language

\n
","metadata":{"tags":[]}},{"cell_type":"markdown","source":"

Example of a compiled language

\n
","metadata":{}},{"cell_type":"markdown","source":"

Example of a compiled language

\n
","metadata":{}},{"cell_type":"markdown","source":"

Let’s get started

\n\n\n","metadata":{"tags":[]}},{"cell_type":"markdown","source":"\n\n\n\n\n\n
Crash course on C++
\n
THE VERY (VERY!) BASICS OF C++
\n","metadata":{"slideshow":{"slide_type":"slide"},"tags":[]}},{"cell_type":"markdown","source":"

Comments

\n","metadata":{"slideshow":{"slide_type":"slide"},"tags":[]}},{"cell_type":"code","source":"/**\nComments\n* \\file hello.cxx\n*\n* This file is part of the course tw3720tu:\n* Object Oriented Scientific Programming with C++ *\n* \\author Matthias Moller\n*/","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":14,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{"slideshow":{"slide_type":"fragment"},"tags":[]}},{"cell_type":"markdown","source":"

Comments

\n","metadata":{"slideshow":{"slide_type":"subslide"}}},{"cell_type":"code","source":"/**\n \\file hello.cxx\nThis file is part of the course tw3720tu: Object Oriented Scientific Programming with C++\n \\author Matthias Moller\n*/","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":15,"outputs":[]},{"cell_type":"markdown","source":"

Comments

\n","metadata":{"slideshow":{"slide_type":"subslide"}}},{"cell_type":"code","source":"//\n// \\file hello.cxx\n//\n// This file is part of the course tw3720tu:\n// Object Oriented Scientific Programming with C++ //\n// \\author Matthias Moller","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":16,"outputs":[]},{"cell_type":"markdown","source":"

Comments

\n","metadata":{"slideshow":{"slide_type":"subslide"},"tags":[]}},{"cell_type":"code","source":"/**\n* This function computes the factorial of a number * \\bug John Doe broke it last night. Fix it!!!\n*/","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":17,"outputs":[]},{"cell_type":"markdown","source":"

and // for short comments also at the end of a code line

","metadata":{"slideshow":{"slide_type":"fragment"}}},{"cell_type":"code","source":"int a = 1, b = a+2, c = 3+b; //can be done in one line","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":18,"outputs":[]},{"cell_type":"markdown","source":"

Hello World!

","metadata":{"slideshow":{"slide_type":"slide"}}},{"cell_type":"code","source":"// Include header file for standard input/output stream library\n#include \n/**\n * The global main function that is the designated start of the program\n */\nint main(){\n /**\n * Write the string 'Hello world!' to the default output stream and\n * terminate with a new line (that is what std::endl does)\n */\n std::cout<<\"Hello world!\"<
Hello World!
\n
    \n
  • Extra functionality provided by the standard C++ library is defined in so-called header files which need to be included via #include <headerfile> \n
      \n
    • iostream: input/output\n
    • \n
    • string: string types\n
    • \n
    • complex: complex numbers\n
    • \n
    • Good overview : http://www.cplusplus.com
    • \n
    \n
  • \n
  • We will write our own header files later in this course
  • \n
","metadata":{"slideshow":{"slide_type":"subslide"}}},{"cell_type":"markdown","source":"

THE main function

\n
    \n
  • Each C++ program must provide one (and only one!) global main function which is the designated start of the program
  • \n

    int main() { body } OR

    \n

    int main(int argc, char* argv[]) { body }

    \n
  • Scope of the main function {...}
  • \n
  • Return type of the main function is int (=integer)
  • \n

    return 0;

    \n
  • Main function cannot be called recursively
  • \n
","metadata":{"slideshow":{"slide_type":"slide"}}},{"cell_type":"markdown","source":"

Standard output

\n
    \n
  • Stream-based output system
  • \n

    std::cout << \"Hello world!\" << std::endl;

    \n
  • Streams can be easily concatenated
  • \n

    std::cout << \"Hello\" << \" \" << \"world!\" << std::endl;

    \n
  • Streams are part of the standard C++ library and therefore encapsulated in the namespace std (later in this lecture)
  • \n
  • Predefined output streams
  • \n

    return 0;

    \n
  • Main function cannot be called recursively
  • \n
      \n
    • std::cout : standard output stream
    • \n
    • std::cerr : standard output stream for errors
    • \n
    • std::clog : standard output stream for logging
    • \n
    \n
","metadata":{"slideshow":{"slide_type":"slide"}}},{"cell_type":"markdown","source":"

Try youself

","metadata":{"slideshow":{"slide_type":"subslide"}}},{"cell_type":"code","source":"std::cout << \"Hello world!\" << std::endl;\nstd::cout << \"Hello\" << \" \" << \"world!\" << std::endl;","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":3,"outputs":[{"name":"stdout","text":"Hello world!\nHello world!\n","output_type":"stream"}]},{"cell_type":"markdown","source":"

Variables and constants

\n
    \n
  • C++ is case sensitive and typed, that is, variables and constants have a value and a concrete type\n
  • \n
","metadata":{"slideshow":{"slide_type":"slide"}}},{"cell_type":"code","source":"int a = 10; // integer variable initialized to 10\na = 15;//This is valid","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":4,"outputs":[{"execution_count":4,"output_type":"execute_result","data":{"text/plain":"15"},"metadata":{}}]},{"cell_type":"markdown","source":"Try add keyword const in front of int a.\n
    \n
  • \nVariables can be updated, constants cannot\n
  • \n
","metadata":{"slideshow":{"slide_type":"fragment"}}},{"cell_type":"code","source":"int a = 10; \nconst int b = 20; //integer constant initialized to 20","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":5,"outputs":[]},{"cell_type":"code","source":"a = b;\nb = a; ","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":6,"outputs":[{"name":"stderr","text":"input_line_19:3:3: error: cannot assign to variable 'b' with const-qualified type 'const int'\nb = a; \n~ ^\ninput_line_18:3:11: note: variable 'b' declared const here\nconst int b = 20; //integer constant initialized to 20\n~~~~~~~~~~^~~~~~\n","output_type":"stream"},{"ename":"Interpreter Error","evalue":"","traceback":["Interpreter Error: "],"output_type":"error"}]},{"cell_type":"markdown","source":"
    \n
  • \nVariables and constants can be defined everywhere in the code (not just at the beginning). They are valid from the moment that they are defined to the end of their scope\n
  • \n
","metadata":{"slideshow":{"slide_type":"fragment"}}},{"cell_type":"markdown","source":"

Initialisation of variables/constants

\n
    \n
  • \nConstants must be initialised during their definition\n
  • \n
","metadata":{"slideshow":{"slide_type":"subslide"},"tags":[]}},{"cell_type":"code","source":"const int c = 20; // C-like initialisation\nconst int d(20); // constructor initialisation\nconst int e = {20}; // uniform initialisation, since C++11 \nconst int f{20};","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":7,"outputs":[]},{"cell_type":"markdown","source":"

Initialisation of variables/constants

\n
    \n
  • \n Variables can be initialised during their definition or (since they are variable) at any location later in the code\n
  • \n
","metadata":{"slideshow":{"slide_type":"subslide"}}},{"cell_type":"code","source":"int g = 10; // C-like initialisation\nint h(20); // constructor initialisation\nint i = {20}; // uniform initialisation, since C++11\nint j; // only declaration (arbitrary value!)\nj = 20; // assignment of value","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":8,"outputs":[{"execution_count":8,"output_type":"execute_result","data":{"text/plain":"20"},"metadata":{}}]},{"cell_type":"markdown","source":"

Intermezzo: Terminology

\n
    \n
  • A declaration introduces the name of the variable or constant, and describes its type but does not create it\n
  • \n

    extern int f;

    \n
  • A definition instantiates it (=creates it)\n
  • \n

    int f;

    \n
  • An initialisation initialises it (=assigns a value to it)\n
  • \n

    f = 10;

    \n
  • All three steps can be combined, e.g., int f{10} or split across different source/header files (later in this course)\n
  • \n
","metadata":{"slideshow":{"slide_type":"slide"}}},{"cell_type":"markdown","source":"

Scope of variables/constants

\n
    \n
  • Variables/constants are only visible in their scope\n
  • \n
","metadata":{"slideshow":{"slide_type":"slide"}}},{"cell_type":"code","source":"int main() {\n int a = 10; // variable a is visible here\n {\n int b = a; // variable a is visible here\n }\n}","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":9,"outputs":[]},{"cell_type":"markdown","source":"

Scope of variables/constants

\n
    \n
  • Variables/constants are only visible in their scope\n
  • \n
","metadata":{"slideshow":{"slide_type":"subslide"}}},{"cell_type":"code","source":"int main() {\n int a = 10; // variable a is visible here\n {\n int b = a; // variable a is visible here\n }\n {\n int c = b; // variable a is visible here, \n } //b is not(!) visible here -> error\n}","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":10,"outputs":[]},{"cell_type":"markdown","source":"

Scope of variables/constants

\n
    \n
  • Variables/constants are only visible in their scope\n
  • \n

    More examples

    \n
","metadata":{"slideshow":{"slide_type":"subslide"}}},{"cell_type":"code","source":"int main() {\n int a = 10; // variable a is visible here\n {\n int a = 20; // new variable a only visible in blue\n // scope, interrupts scope of red one\n std::cout << a << std::endl; // is 20\n}\n std::cout << a << std::endl; // is 10\n }","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":11,"outputs":[]},{"cell_type":"markdown","source":"

C++ standard types

","metadata":{"slideshow":{"slide_type":"slide"}}},{"cell_type":"markdown","source":"\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
GroupType nameNotes on size / precision
Character typescharExactly one byte in size. At least 8 bits.
char16_tNot smaller than char. At least 16 bits.
char32_tNot smaller than char16_t. At least 32 bits.
Integer types (signed and unsigned)(un)signed charSame size as char. At least 8 bits.
(un)signed short intNot smaller than char. At least 16 bits.
(un)signed intNot smaller than short. At least 16 bits.
(un)signed long intNot smaller than int. At least 32 bits.
(un)signed long long intNot smaller than long. At least 64 bits.
Floating-point typefloatPrecision not less than float
doublePrecision not less than float
long doublePrecision not less than double
Boolean typebool
","metadata":{"slideshow":{"slide_type":"fragment"}}},{"cell_type":"markdown","source":"

Examples of C++ types

\n
    \n
  • \n Double-precision floating-point type\n
  • \n
","metadata":{"slideshow":{"slide_type":"slide"}}},{"cell_type":"code","source":"double d1 = 1.0;\ndouble d2 = 1.; // zero is added automatically\ndouble d3 = 1e3; // -> 1000\ndouble d4 = 1.5E3; // -> 1500\ndouble d5 = 15e-2; // -> 0.15","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":12,"outputs":[]},{"cell_type":"markdown","source":"
    \n
  • \n Single-precision floating-point type\n
  • \n
","metadata":{"slideshow":{"slide_type":"fragment"}}},{"cell_type":"code","source":"float f1 = 1.0f; // or 1.0F suffix type specifier\nfloat f2 = 1.0; // works the same but does conversion\nfloat f3 = 1.5e3F; // -> 1500","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":14,"outputs":[]},{"cell_type":"markdown","source":"

Mixing and conversion of types

\n
    \n
  • \n Getting the type of a variable\n
  • \n
","metadata":{"slideshow":{"slide_type":"slide"}}},{"cell_type":"code","source":"#include \nfloat f = 1.7f; double d = 0.7; // float\nstd::cout << typeid(f).name() << std::endl; std::cout << typeid(d).name() << std::endl; // double","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":16,"outputs":[{"name":"stdout","text":"f\nd\n","output_type":"stream"},{"execution_count":16,"output_type":"execute_result","data":{"text/plain":"@0x7fa2f0729de0"},"metadata":{}}]},{"cell_type":"markdown","source":"
    \n
  • C++ converts different types automatically\n
  • \n
","metadata":{"slideshow":{"slide_type":"fragment"}}},{"cell_type":"code","source":"std::cout << typeid(f+d).name() << std::endl; // double","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":17,"outputs":[{"name":"stdout","text":"d\n","output_type":"stream"},{"execution_count":17,"output_type":"execute_result","data":{"text/plain":"@0x7fa2f0729de0"},"metadata":{}}]},{"cell_type":"markdown","source":"
    \n
  • Check if you are happy with the result\n
  • \n
","metadata":{"slideshow":{"slide_type":"fragment"}}},{"cell_type":"code","source":"char x = 'a'; \nfloat y = 1.7;\nstd::cout << typeid(x+y).name() << std::endl; // float???","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":19,"outputs":[{"name":"stdout","text":"f\n","output_type":"stream"},{"execution_count":19,"output_type":"execute_result","data":{"text/plain":"@0x7fa2f0729de0"},"metadata":{}}]},{"cell_type":"markdown","source":"

Mixing and conversion of types

\n
    \n
  • \n C++11 introduces the auto keyword, which makes handling\nof mixed types very easy (other advantages will follow)\n
  • \n
","metadata":{"slideshow":{"slide_type":"subslide"}}},{"cell_type":"code","source":"auto x = f+d;\nstd::cout << typeid(x).name() << std::endl; // double","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":20,"outputs":[{"name":"stdout","text":"d\n","output_type":"stream"},{"execution_count":20,"output_type":"execute_result","data":{"text/plain":"@0x7fa2f0729de0"},"metadata":{}}]},{"cell_type":"markdown","source":"
    \n
  • \n You can also explicitly cast one type into another\n
  • \n
","metadata":{"slideshow":{"slide_type":"fragment"}}},{"cell_type":"code","source":"auto y = f + (float)d;\nstd::cout << typeid(y).name() << std::endl; // float\n \nauto z = (int) (f + (float)d);\nstd::cout << typeid(z).name() << std::endl; // int","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":21,"outputs":[{"name":"stdout","text":"f\ni\n","output_type":"stream"},{"execution_count":21,"output_type":"execute_result","data":{"text/plain":"@0x7fa2f0729de0"},"metadata":{}}]},{"cell_type":"markdown","source":"

Auto vs. explicit types

\n
    \n
  • Recommendation: use the keyword auto ...
  • \n
      \n
    • to improve readability of the source code
    • \n
    • to improve maintainability of the source code
    • \n
    • to benefit from performance gains (later in this course)
    • \n
    \n
  • ... unless explicit conversion is required
  • \n
      \n
    • auto a = 1.5+0.3; // is (double)1.8 = 1.8
    • \n
    • int b = 1.5+0.3; // is (int)1.8 = 1
    • \n
    \n
  • ... unless the C++ standard does not allow so, e.g. return type of a (pure) virtual function (later in this course)
  • \n
","metadata":{"slideshow":{"slide_type":"slide"}}},{"cell_type":"markdown","source":"

Use of suffix type specifiers

\n
    \n
  • Suffix type specifiers (termed literals) seem unnecessary at first glance since constants are implicitly converted
  • \n
      \n
    • float f1 = 0.67;
    • \n
    \n
  • But keep in mind that 0.67 and 0.67f are not the same
  • \n
      \n
    • std::cout << (f1 == 0.67); // -> false
    • \n
    • std::cout << (f1 == 0.67f); // -> true
    • \n
    \n
","metadata":{"slideshow":{"slide_type":"slide"}}},{"cell_type":"code","source":"float f1 = 0.67;\nstd::cout<<(f1 == 0.67); \nstd::cout<<(f1 == 0.67f);","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":23,"outputs":[{"name":"stdout","text":"01","output_type":"stream"}]},{"cell_type":"markdown","source":"

Address-of/dereference operators

\n
\n
    \n
  • Integer variable
  • \n
      \n
    • int i = 10;
    • \n
    \n
  • Pointer to its address
  • \n
      \n
    • auto p = &i;
    • \n
    \n
  • Dereference to its value
  • \n
      \n
    • int j = *p
    • \n
    \n
\n
\n
\n\n
","metadata":{"slideshow":{"slide_type":"slide"}}},{"cell_type":"code","source":"int i = 10;\nauto p = &i;\nint j = *p;","metadata":{"trusted":true,"tags":[]},"execution_count":44,"outputs":[]},{"cell_type":"markdown","source":"

Address-of/dereference operators

\n
    \n
  • Address-of operator (&) returns the address of a variable\n(= its physical location in the computer’s main memory)\n
  • \n
","metadata":{"slideshow":{"slide_type":"slide"}}},{"cell_type":"code","source":"int i = 10;\nauto p = &i;\nstd::cout<') and 'int *')\nstd::cout<& __out, char __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:517:5: note: candidate function template not viable: no known conversion from 'int *' to 'char' for 2nd argument; dereference the argument with *\n operator<<(basic_ostream& __out, char __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:523:5: note: candidate function template not viable: no known conversion from 'int *' to 'signed char' for 2nd argument; dereference the argument with *\n operator<<(basic_ostream& __out, signed char __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:528:5: note: candidate function template not viable: no known conversion from 'int *' to 'unsigned char' for 2nd argument; dereference the argument with *\n operator<<(basic_ostream& __out, unsigned char __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/cstddef:125:5: note: candidate function template not viable: no known conversion from 'std::ostream' (aka 'basic_ostream') to 'std::byte' for 1st argument\n operator<<(byte __b, _IntegerType __shift) noexcept\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/system_error:262:5: note: candidate function template not viable: no known conversion from 'int *' to 'const std::error_code' for 2nd argument\n operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:108:7: note: candidate function not viable: no known conversion from 'int *' to 'std::basic_ostream >::__ostream_type &(*)(std::basic_ostream >::__ostream_type &)' (aka 'basic_ostream > &(*)(basic_ostream > &)') for 1st argument\n operator<<(__ostream_type& (*__pf)(__ostream_type&))\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:117:7: note: candidate function not viable: no known conversion from 'int *' to 'std::basic_ostream >::__ios_type &(*)(std::basic_ostream >::__ios_type &)' (aka 'basic_ios > &(*)(basic_ios > &)') for 1st argument\n operator<<(__ios_type& (*__pf)(__ios_type&))\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:127:7: note: candidate function not viable: no known conversion from 'int *' to 'std::ios_base &(*)(std::ios_base &)' for 1st argument\n operator<<(ios_base& (*__pf) (ios_base&))\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:250:7: note: candidate function not viable: no known conversion from 'int *' to 'std::nullptr_t' (aka 'nullptr_t') for 1st argument\n operator<<(nullptr_t)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:276:7: note: candidate function not viable: no known conversion from 'int *' to 'std::basic_ostream >::__streambuf_type *' (aka 'basic_streambuf > *') for 1st argument\n operator<<(__streambuf_type* __sb);\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:606:5: note: candidate function template not viable: no known conversion from 'int *' to 'const char *' for 2nd argument\n operator<<(basic_ostream& __out, const char* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:619:5: note: candidate function template not viable: no known conversion from 'int *' to 'const signed char *' for 2nd argument\n operator<<(basic_ostream& __out, const signed char* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:624:5: note: candidate function template not viable: no known conversion from 'int *' to 'const unsigned char *' for 2nd argument\n operator<<(basic_ostream& __out, const unsigned char* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/ostream.tcc:321:5: note: candidate function template not viable: no known conversion from 'int *' to 'const char *' for 2nd argument\n operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:506:5: note: candidate template ignored: deduced conflicting types for parameter '_CharT' ('char' vs. 'int *')\n operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:589:5: note: candidate template ignored: deduced conflicting types for parameter '_CharT' ('char' vs. 'int')\n operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/string_view:621:5: note: candidate template ignored: could not match 'basic_string_view' against 'int *'\n operator<<(basic_ostream<_CharT, _Traits>& __os,\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/basic_string.h:6480:5: note: candidate template ignored: could not match 'basic_string' against 'int *'\n operator<<(basic_ostream<_CharT, _Traits>& __os,\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/shared_ptr.h:69:5: note: candidate template ignored: could not match '__shared_ptr' against 'int *'\n operator<<(std::basic_ostream<_Ch, _Tr>& __os,\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'basic_ostream'\n _DEFINE_EXPR_BINARY_OPERATOR(<<, struct std::__shift_left)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:344:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const _Expr<_Dom1, typename _Dom1::value_type>& __v, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'basic_ostream'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:357:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const _Expr<_Dom, typename _Dom::value_type>& __v, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'int *'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:370:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const typename _Dom::value_type& __t, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'basic_ostream'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:383:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const _Expr<_Dom,typename _Dom::value_type>& __e, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'int *'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:396:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const valarray& __v, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1193:1: note: candidate template ignored: could not match 'valarray' against 'basic_ostream'\n_DEFINE_BINARY_OPERATOR(<<, __shift_left)\n^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1155:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR'\n operator _Op(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1193:1: note: candidate template ignored: could not match 'valarray' against 'basic_ostream'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1166:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR'\n operator _Op(const valarray<_Tp>& __v, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1193:1: note: candidate template ignored: could not match 'valarray' against 'int *'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1177:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR'\n operator _Op(const typename valarray<_Tp>::value_type& __t, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:773:5: note: candidate template ignored: substitution failure [with _Ostream = std::basic_ostream &, _Tp = int *]: no member named 'value' in 'std::__and_ &> >, std::__is_convertible_to_basic_ostream &>, std::__is_insertable &, int *const &, void> >'\n operator<<(_Ostream&& __os, const _Tp& __x)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/complex:554:5: note: candidate template ignored: could not match 'complex' against 'int *'\n operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x)\n ^\n","output_type":"stream"},{"ename":"Interpreter Error","evalue":"","traceback":["Interpreter Error: "],"output_type":"error"}]},{"cell_type":"code","source":"
    \n
  • Addresses are of pointer type (equal to that of the variable)\n
  • \n
","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":33,"outputs":[{"name":"stderr","text":"input_line_54:2:2: error: expected expression\n
    \n ^\ninput_line_54:2:3: error: use of undeclared identifier 'ul'\n
      \n ^\ninput_line_54:3:5: error: expected expression\n
    • Addresses are of pointer type (equal to that of the variable)\n ^\ninput_line_54:3:6: error: use of undeclared identifier 'li'\n
    • Addresses are of pointer type (equal to that of the variable)\n ^\ninput_line_54:3:10: error: use of undeclared identifier 'Addresses'\n
    • Addresses are of pointer type (equal to that of the variable)\n ^\n","output_type":"stream"},{"ename":"Interpreter Error","evalue":"","traceback":["Interpreter Error: "],"output_type":"error"}]},{"cell_type":"code","source":"std::cout << typeid(i).name() << std::endl; // i\nstd::cout << typeid(p).name() << std::endl; // Pi","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":34,"outputs":[{"name":"stderr","text":"input_line_55:2:22: error: use of undeclared identifier 'i'\n std::cout << typeid(i).name() << std::endl; // i\n ^\ninput_line_55:3:21: error: use of undeclared identifier 'p'\nstd::cout << typeid(p).name() << std::endl; // Pi\n ^\n","output_type":"stream"},{"ename":"Interpreter Error","evalue":"","traceback":["Interpreter Error: "],"output_type":"error"}]},{"cell_type":"code","source":"
        \n
      • Addresses are of Dereference operator (*) returns value behind the pointer\n
      • \n
      ","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":35,"outputs":[{"name":"stderr","text":"input_line_56:2:2: error: expected expression\n
        \n ^\ninput_line_56:2:3: error: use of undeclared identifier 'ul'\n
          \n ^\ninput_line_56:3:5: error: expected expression\n
        • Addresses are of Dereference operator (*) returns value behind the pointer\n ^\ninput_line_56:3:6: error: use of undeclared identifier 'li'\n
        • Addresses are of Dereference operator (*) returns value behind the pointer\n ^\ninput_line_56:3:10: error: use of undeclared identifier 'Addresses'\n
        • Addresses are of Dereference operator (*) returns value behind the pointer\n ^\n","output_type":"stream"},{"ename":"Interpreter Error","evalue":"","traceback":["Interpreter Error: "],"output_type":"error"}]},{"cell_type":"code","source":"std::cout<<*p<
          Pointers and references
          \n
            \n
          • Pointers can be used to have multiple variables (with\ndifferent names) pointing to the same value\n
          • \n
          ","metadata":{"slideshow":{"slide_type":"slide"}}},{"cell_type":"code","source":"int i = 10;\nint* p = &i;","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":36,"outputs":[]},{"cell_type":"markdown","source":"
            \n
          • Change the value of variable i\n
          • \n
          ","metadata":{"slideshow":{"slide_type":"fragment"}}},{"cell_type":"code","source":"i = 20; std::cout << *p << std::endl; // *p is 20","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":37,"outputs":[{"name":"stdout","text":"20\n","output_type":"stream"},{"execution_count":37,"output_type":"execute_result","data":{"text/plain":"@0x7fa2f0729de0"},"metadata":{}}]},{"cell_type":"markdown","source":"
            \n
          • Dereference pointer p and change its value\n
          • \n
          ","metadata":{"slideshow":{"slide_type":"fragment"}}},{"cell_type":"code","source":"*p = 30; std::cout << i << std::endl; // i is 30","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":38,"outputs":[{"name":"stdout","text":"30\n","output_type":"stream"},{"execution_count":38,"output_type":"execute_result","data":{"text/plain":"@0x7fa2f0729de0"},"metadata":{}}]},{"cell_type":"markdown","source":"
            \n
          • Change value of pointer p without dereferencing\n
          • \n
          ","metadata":{"slideshow":{"slide_type":"fragment"}}},{"cell_type":"code","source":"p = p+1; \nstd::cout << p << std::endl; // p is 0x0008\nstd::cout << *p << std::endl; // *p is CRAP","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":40,"outputs":[{"name":"stderr","text":"input_line_63:3:11: error: invalid operands to binary expression ('std::ostream' (aka 'basic_ostream') and 'int *')\nstd::cout << p << std::endl; // p is 0x0008\n~~~~~~~~~ ^ ~\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:166:7: note: candidate function not viable: no known conversion from 'int *' to 'long' for 1st argument; dereference the argument with *\n operator<<(long __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:170:7: note: candidate function not viable: no known conversion from 'int *' to 'unsigned long' for 1st argument; dereference the argument with *\n operator<<(unsigned long __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:178:7: note: candidate function not viable: no known conversion from 'int *' to 'short' for 1st argument; dereference the argument with *\n operator<<(short __n);\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:181:7: note: candidate function not viable: no known conversion from 'int *' to 'unsigned short' for 1st argument; dereference the argument with *\n operator<<(unsigned short __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:189:7: note: candidate function not viable: no known conversion from 'int *' to 'int' for 1st argument; dereference the argument with *\n operator<<(int __n);\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:192:7: note: candidate function not viable: no known conversion from 'int *' to 'unsigned int' for 1st argument; dereference the argument with *\n operator<<(unsigned int __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:201:7: note: candidate function not viable: no known conversion from 'int *' to 'long long' for 1st argument; dereference the argument with *\n operator<<(long long __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:205:7: note: candidate function not viable: no known conversion from 'int *' to 'unsigned long long' for 1st argument; dereference the argument with *\n operator<<(unsigned long long __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:220:7: note: candidate function not viable: no known conversion from 'int *' to 'double' for 1st argument; dereference the argument with *\n operator<<(double __f)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:224:7: note: candidate function not viable: no known conversion from 'int *' to 'float' for 1st argument; dereference the argument with *\n operator<<(float __f)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:232:7: note: candidate function not viable: no known conversion from 'int *' to 'long double' for 1st argument; dereference the argument with *\n operator<<(long double __f)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:511:5: note: candidate function template not viable: no known conversion from 'int *' to 'char' for 2nd argument; dereference the argument with *\n operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:517:5: note: candidate function template not viable: no known conversion from 'int *' to 'char' for 2nd argument; dereference the argument with *\n operator<<(basic_ostream& __out, char __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:523:5: note: candidate function template not viable: no known conversion from 'int *' to 'signed char' for 2nd argument; dereference the argument with *\n operator<<(basic_ostream& __out, signed char __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:528:5: note: candidate function template not viable: no known conversion from 'int *' to 'unsigned char' for 2nd argument; dereference the argument with *\n operator<<(basic_ostream& __out, unsigned char __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/cstddef:125:5: note: candidate function template not viable: no known conversion from 'std::ostream' (aka 'basic_ostream') to 'std::byte' for 1st argument\n operator<<(byte __b, _IntegerType __shift) noexcept\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/system_error:262:5: note: candidate function template not viable: no known conversion from 'int *' to 'const std::error_code' for 2nd argument\n operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:108:7: note: candidate function not viable: no known conversion from 'int *' to 'std::basic_ostream >::__ostream_type &(*)(std::basic_ostream >::__ostream_type &)' (aka 'basic_ostream > &(*)(basic_ostream > &)') for 1st argument\n operator<<(__ostream_type& (*__pf)(__ostream_type&))\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:117:7: note: candidate function not viable: no known conversion from 'int *' to 'std::basic_ostream >::__ios_type &(*)(std::basic_ostream >::__ios_type &)' (aka 'basic_ios > &(*)(basic_ios > &)') for 1st argument\n operator<<(__ios_type& (*__pf)(__ios_type&))\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:127:7: note: candidate function not viable: no known conversion from 'int *' to 'std::ios_base &(*)(std::ios_base &)' for 1st argument\n operator<<(ios_base& (*__pf) (ios_base&))\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:250:7: note: candidate function not viable: no known conversion from 'int *' to 'std::nullptr_t' (aka 'nullptr_t') for 1st argument\n operator<<(nullptr_t)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:276:7: note: candidate function not viable: no known conversion from 'int *' to 'std::basic_ostream >::__streambuf_type *' (aka 'basic_streambuf > *') for 1st argument\n operator<<(__streambuf_type* __sb);\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:606:5: note: candidate function template not viable: no known conversion from 'int *' to 'const char *' for 2nd argument\n operator<<(basic_ostream& __out, const char* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:619:5: note: candidate function template not viable: no known conversion from 'int *' to 'const signed char *' for 2nd argument\n operator<<(basic_ostream& __out, const signed char* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:624:5: note: candidate function template not viable: no known conversion from 'int *' to 'const unsigned char *' for 2nd argument\n operator<<(basic_ostream& __out, const unsigned char* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/ostream.tcc:321:5: note: candidate function template not viable: no known conversion from 'int *' to 'const char *' for 2nd argument\n operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:506:5: note: candidate template ignored: deduced conflicting types for parameter '_CharT' ('char' vs. 'int *')\n operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:589:5: note: candidate template ignored: deduced conflicting types for parameter '_CharT' ('char' vs. 'int')\n operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/string_view:621:5: note: candidate template ignored: could not match 'basic_string_view' against 'int *'\n operator<<(basic_ostream<_CharT, _Traits>& __os,\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/basic_string.h:6480:5: note: candidate template ignored: could not match 'basic_string' against 'int *'\n operator<<(basic_ostream<_CharT, _Traits>& __os,\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/shared_ptr.h:69:5: note: candidate template ignored: could not match '__shared_ptr' against 'int *'\n operator<<(std::basic_ostream<_Ch, _Tr>& __os,\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'basic_ostream'\n _DEFINE_EXPR_BINARY_OPERATOR(<<, struct std::__shift_left)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:344:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const _Expr<_Dom1, typename _Dom1::value_type>& __v, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'basic_ostream'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:357:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const _Expr<_Dom, typename _Dom::value_type>& __v, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'int *'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:370:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const typename _Dom::value_type& __t, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'basic_ostream'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:383:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const _Expr<_Dom,typename _Dom::value_type>& __e, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'int *'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:396:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const valarray& __v, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1193:1: note: candidate template ignored: could not match 'valarray' against 'basic_ostream'\n_DEFINE_BINARY_OPERATOR(<<, __shift_left)\n^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1155:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR'\n operator _Op(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1193:1: note: candidate template ignored: could not match 'valarray' against 'basic_ostream'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1166:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR'\n operator _Op(const valarray<_Tp>& __v, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1193:1: note: candidate template ignored: could not match 'valarray' against 'int *'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1177:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR'\n operator _Op(const typename valarray<_Tp>::value_type& __t, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:773:5: note: candidate template ignored: substitution failure [with _Ostream = std::basic_ostream &, _Tp = int *]: no member named 'value' in 'std::__and_ &> >, std::__is_convertible_to_basic_ostream &>, std::__is_insertable &, int *const &, void> >'\n operator<<(_Ostream&& __os, const _Tp& __x)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/complex:554:5: note: candidate template ignored: could not match 'complex' against 'int *'\n operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x)\n ^\n","output_type":"stream"},{"ename":"Interpreter Error","evalue":"","traceback":["Interpreter Error: "],"output_type":"error"}]},{"cell_type":"markdown","source":"

          Pointer hazards

          \n
            \n
          • Pointers that remain uninitialized can cause hazard\n
          • \n
          ","metadata":{"slideshow":{"slide_type":"slide"}}},{"cell_type":"code","source":"int* p;\nstd::cout << p << std::endl; // is 0x0008\nstd::cout << *p << std::endl; // is 1449186548","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":41,"outputs":[{"name":"stderr","text":"input_line_64:3:11: error: invalid operands to binary expression ('std::ostream' (aka 'basic_ostream') and 'int *')\nstd::cout << p << std::endl; // is 0x0008\n~~~~~~~~~ ^ ~\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:166:7: note: candidate function not viable: no known conversion from 'int *' to 'long' for 1st argument; dereference the argument with *\n operator<<(long __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:170:7: note: candidate function not viable: no known conversion from 'int *' to 'unsigned long' for 1st argument; dereference the argument with *\n operator<<(unsigned long __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:178:7: note: candidate function not viable: no known conversion from 'int *' to 'short' for 1st argument; dereference the argument with *\n operator<<(short __n);\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:181:7: note: candidate function not viable: no known conversion from 'int *' to 'unsigned short' for 1st argument; dereference the argument with *\n operator<<(unsigned short __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:189:7: note: candidate function not viable: no known conversion from 'int *' to 'int' for 1st argument; dereference the argument with *\n operator<<(int __n);\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:192:7: note: candidate function not viable: no known conversion from 'int *' to 'unsigned int' for 1st argument; dereference the argument with *\n operator<<(unsigned int __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:201:7: note: candidate function not viable: no known conversion from 'int *' to 'long long' for 1st argument; dereference the argument with *\n operator<<(long long __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:205:7: note: candidate function not viable: no known conversion from 'int *' to 'unsigned long long' for 1st argument; dereference the argument with *\n operator<<(unsigned long long __n)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:220:7: note: candidate function not viable: no known conversion from 'int *' to 'double' for 1st argument; dereference the argument with *\n operator<<(double __f)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:224:7: note: candidate function not viable: no known conversion from 'int *' to 'float' for 1st argument; dereference the argument with *\n operator<<(float __f)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:232:7: note: candidate function not viable: no known conversion from 'int *' to 'long double' for 1st argument; dereference the argument with *\n operator<<(long double __f)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:511:5: note: candidate function template not viable: no known conversion from 'int *' to 'char' for 2nd argument; dereference the argument with *\n operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:517:5: note: candidate function template not viable: no known conversion from 'int *' to 'char' for 2nd argument; dereference the argument with *\n operator<<(basic_ostream& __out, char __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:523:5: note: candidate function template not viable: no known conversion from 'int *' to 'signed char' for 2nd argument; dereference the argument with *\n operator<<(basic_ostream& __out, signed char __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:528:5: note: candidate function template not viable: no known conversion from 'int *' to 'unsigned char' for 2nd argument; dereference the argument with *\n operator<<(basic_ostream& __out, unsigned char __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/cstddef:125:5: note: candidate function template not viable: no known conversion from 'std::ostream' (aka 'basic_ostream') to 'std::byte' for 1st argument\n operator<<(byte __b, _IntegerType __shift) noexcept\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/system_error:262:5: note: candidate function template not viable: no known conversion from 'int *' to 'const std::error_code' for 2nd argument\n operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:108:7: note: candidate function not viable: no known conversion from 'int *' to 'std::basic_ostream >::__ostream_type &(*)(std::basic_ostream >::__ostream_type &)' (aka 'basic_ostream > &(*)(basic_ostream > &)') for 1st argument\n operator<<(__ostream_type& (*__pf)(__ostream_type&))\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:117:7: note: candidate function not viable: no known conversion from 'int *' to 'std::basic_ostream >::__ios_type &(*)(std::basic_ostream >::__ios_type &)' (aka 'basic_ios > &(*)(basic_ios > &)') for 1st argument\n operator<<(__ios_type& (*__pf)(__ios_type&))\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:127:7: note: candidate function not viable: no known conversion from 'int *' to 'std::ios_base &(*)(std::ios_base &)' for 1st argument\n operator<<(ios_base& (*__pf) (ios_base&))\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:250:7: note: candidate function not viable: no known conversion from 'int *' to 'std::nullptr_t' (aka 'nullptr_t') for 1st argument\n operator<<(nullptr_t)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:276:7: note: candidate function not viable: no known conversion from 'int *' to 'std::basic_ostream >::__streambuf_type *' (aka 'basic_streambuf > *') for 1st argument\n operator<<(__streambuf_type* __sb);\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:606:5: note: candidate function template not viable: no known conversion from 'int *' to 'const char *' for 2nd argument\n operator<<(basic_ostream& __out, const char* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:619:5: note: candidate function template not viable: no known conversion from 'int *' to 'const signed char *' for 2nd argument\n operator<<(basic_ostream& __out, const signed char* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:624:5: note: candidate function template not viable: no known conversion from 'int *' to 'const unsigned char *' for 2nd argument\n operator<<(basic_ostream& __out, const unsigned char* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/ostream.tcc:321:5: note: candidate function template not viable: no known conversion from 'int *' to 'const char *' for 2nd argument\n operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:506:5: note: candidate template ignored: deduced conflicting types for parameter '_CharT' ('char' vs. 'int *')\n operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:589:5: note: candidate template ignored: deduced conflicting types for parameter '_CharT' ('char' vs. 'int')\n operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/string_view:621:5: note: candidate template ignored: could not match 'basic_string_view' against 'int *'\n operator<<(basic_ostream<_CharT, _Traits>& __os,\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/basic_string.h:6480:5: note: candidate template ignored: could not match 'basic_string' against 'int *'\n operator<<(basic_ostream<_CharT, _Traits>& __os,\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/shared_ptr.h:69:5: note: candidate template ignored: could not match '__shared_ptr' against 'int *'\n operator<<(std::basic_ostream<_Ch, _Tr>& __os,\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'basic_ostream'\n _DEFINE_EXPR_BINARY_OPERATOR(<<, struct std::__shift_left)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:344:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const _Expr<_Dom1, typename _Dom1::value_type>& __v, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'basic_ostream'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:357:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const _Expr<_Dom, typename _Dom::value_type>& __v, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'int *'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:370:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const typename _Dom::value_type& __t, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'basic_ostream'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:383:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const _Expr<_Dom,typename _Dom::value_type>& __e, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:413:5: note: candidate template ignored: could not match '_Expr' against 'int *'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/bits/valarray_after.h:396:5: note: expanded from macro '_DEFINE_EXPR_BINARY_OPERATOR'\n operator _Op(const valarray& __v, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1193:1: note: candidate template ignored: could not match 'valarray' against 'basic_ostream'\n_DEFINE_BINARY_OPERATOR(<<, __shift_left)\n^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1155:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR'\n operator _Op(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1193:1: note: candidate template ignored: could not match 'valarray' against 'basic_ostream'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1166:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR'\n operator _Op(const valarray<_Tp>& __v, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1193:1: note: candidate template ignored: could not match 'valarray' against 'int *'\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/valarray:1177:5: note: expanded from macro '_DEFINE_BINARY_OPERATOR'\n operator _Op(const typename valarray<_Tp>::value_type& __t, \\\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/ostream:773:5: note: candidate template ignored: substitution failure [with _Ostream = std::basic_ostream &, _Tp = int *]: no member named 'value' in 'std::__and_ &> >, std::__is_convertible_to_basic_ostream &>, std::__is_insertable &, int *const &, void> >'\n operator<<(_Ostream&& __os, const _Tp& __x)\n ^\n/srv/conda/envs/notebook/bin/../lib/gcc/../../x86_64-conda-linux-gnu/include/c++/10.4.0/complex:554:5: note: candidate template ignored: could not match 'complex' against 'int *'\n operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x)\n ^\n","output_type":"stream"},{"ename":"Interpreter Error","evalue":"","traceback":["Interpreter Error: "],"output_type":"error"}]},{"cell_type":"markdown","source":"
            \n
          • C++11 introduces the new keyword nullptr nullptr\n
          • \n
          ","metadata":{"slideshow":{"slide_type":"fragment"}}},{"cell_type":"code","source":"int * p = nullptr;\nstd::cout << p << std::endl; // is 0x0\nstd::cout << *p << std::endl; // yields Segmentation fault","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"
            \n
          • Think fail-safe!\n
          • \n
          ","metadata":{"slideshow":{"slide_type":"fragment"}}},{"cell_type":"code","source":"std::cout << (p ? *p : NULL) << std::endl;","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":43,"outputs":[{"name":"stderr","text":"input_line_66:2:16: error: use of undeclared identifier 'p'\n std::cout << (p ? *p : NULL) << std::endl;\n ^\ninput_line_66:2:21: error: use of undeclared identifier 'p'\n std::cout << (p ? *p : NULL) << std::endl;\n ^\n","output_type":"stream"},{"ename":"Interpreter Error","evalue":"","traceback":["Interpreter Error: "],"output_type":"error"}]},{"cell_type":"markdown","source":"

          Argument passing – by value

          \n
            \n
          • Arguments are passed by value (C++ default behaviour)\n
          • \n
          ","metadata":{"slideshow":{"slide_type":"slide"}}},{"cell_type":"code","source":"int i = 1;// first variable i=1// second variable j=2 (i=1 still)\nint j = addOne(i);\nint addOne(int a)// third variable a (=copy of i)\n{\nreturn a+1;// increment a by one and copy result\n // to variable j on return\n}","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":52,"outputs":[{"name":"stderr","text":"input_line_75:3:9: error: use of undeclared identifier 'addOne'\nint j = addOne(i);\n ^\ninput_line_75:5:1: error: function definition is not allowed here\n{\n^\n","output_type":"stream"},{"ename":"Interpreter Error","evalue":"","traceback":["Interpreter Error: "],"output_type":"error"}]},{"cell_type":"markdown","source":"
            \n
          • Think big! Do you want to copy gigabytes of data?\n
          • \n
          ","metadata":{"slideshow":{"slide_type":"fragment"}}},{"cell_type":"markdown","source":"

          Argument passing – by reference

          \n
            \n
          • Arguments can be passed by reference\n
          • \n
          ","metadata":{"slideshow":{"slide_type":"subslide"}}},{"cell_type":"code","source":"int i = 1;// first variable i=1\nint j = addOne(i);// second variable j=2 (i=1 still)\nint addOne(int& a)// a is reference to first variable\n{\nreturn a+1;// copy result of a+1\n // to variable j on return\n}","metadata":{"slideshow":{"slide_type":"fragment"}},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"
            \n
          • Think big! Fine, we saved one copy.\n
          • \n
          • Think fail-safe! What if addOne tries to hijack a(=i)?\n
          • \n
          ","metadata":{"slideshow":{"slide_type":"fragment"}}},{"cell_type":"markdown","source":"

          Argument passing – by reference

          \n
            \n
          • Arguments can be passed by reference\n
          • \n
          ","metadata":{"slideshow":{"slide_type":"subslide"}}},{"cell_type":"code","source":"int i = 1; // first variable i=1\nint j = addOne(i); // second variable j=1 (i=2)\nint addOne(int& a) // a is reference to first variable \n{\n return a++; // copy value of a to variable j on\n // return and increment a by one\n}","metadata":{"slideshow":{"slide_type":"fragment"}},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"
            \n
          • Post-increment operator a++\n
          • \n
          ","metadata":{"slideshow":{"slide_type":"fragment"}}},{"cell_type":"markdown","source":"

          Argument passing – by reference

          \n
            \n
          • Arguments can be passed by reference\n
          • \n
          ","metadata":{"slideshow":{"slide_type":"subslide"}}},{"cell_type":"code","source":"int i = 1; // first variable i=1\nint j = addOne(i); // second variable j=2 (i=2)\nint addOne(int& a) // a is reference to first variable \n{\n return ++a; // increment value of a by one and\n // copy result to variable j on return\n}","metadata":{"slideshow":{"slide_type":"fragment"}},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"
            \n
          • Pre-increment operator ++a\n
          • \n
          ","metadata":{"slideshow":{"slide_type":"fragment"}}},{"cell_type":"markdown","source":"

          Argument passing – by const reference

          \n
            \n
          • Arguments can be passed by constant reference\n
          • \n
          ","metadata":{"slideshow":{"slide_type":"subslide"}}},{"cell_type":"code","source":"int i = 1; // first variable i=1\nint j = addOne(i); // second variable j=2 (i=1 still)\nint addOne(const int& a) // a is const reference to a\n {\n return a+1; // copy result of a+1\n // to variable j on return\n}","metadata":{"slideshow":{"slide_type":"fragment"}},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"
            \n
          • Think big! Fine, we saved one copy.\n
          • \n
          • Think fail-safe! Fine, a++ and ++a now gives compiler error.\n
          • \n
              ","metadata":{"slideshow":{"slide_type":"fragment"}}},{"cell_type":"markdown","source":"

              C++ return value optimization (RVO)

              \n

              \n Most C++ compilers support RVO, that is, no temporary variable for the return value is created inside the function\n

              \n
              \nint addOne(const int& a) { return a+1; }\n    
              \n

              \n but the return value is immediately assigned to variable j.\n

              \n
              \nint i = 1;\nint j = addOne(i); // RVO make it int j = (i+1);\n    
              \n

              \n Think big! We finally saved two copies.\n

              ","metadata":{"slideshow":{"slide_type":"subslide"}}},{"cell_type":"markdown","source":"

              Argument passing

              \n

              \n If we want a function that changes the argument directly, we must pass the argument by reference.\n

              \n
              \nint i = 1;       // i=1\naddOne_Val(i);   // i=1 (still)\naddOne_Ref(i);   // i=2\n    
              \n
              \nvoid addOne_Val(int a) { a++; }  // increment local copy\nvoid addOne_Ref(int& a) { a++; } // increment a(~i)\n    
              \n

              \n The return type void indicates that 'nothing' is returned.\n

              ","metadata":{"slideshow":{"slide_type":"subslide"}}},{"cell_type":"markdown","source":"

              Static arrays

              \n

              Definition and creation of a static array:

              \n
              int array[5];
              \n\n

              Definition, creation and initialisation of a static array:

              \n
              int array[5] = { 1, 2, 3, 4, 5 }; // since C++11\nint array[5]{ 1, 2, 3, 4, 5 }; // since C++11
              \n\n

              Access of individual array positions:

              \n","metadata":{"slideshow":{"slide_type":"slide"}}},{"cell_type":"code","source":"for (auto i=0; i<5; i++)\n std::cout << array[i] << std::endl;","metadata":{"slideshow":{"slide_type":"fragment"}},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"

              Remember that C++ starts indexing at 0

              \n

              Static arrays are destroyed automatically at the end of scope

              ","metadata":{"slideshow":{"slide_type":"fragment"}}},{"cell_type":"markdown","source":"

              Quiz: Static arrays

              \n

              What happens?

              ","metadata":{"slideshow":{"slide_type":"slide"}}},{"cell_type":"code","source":"auto array = { 1, 2, 3, 4, 5 };","metadata":{"slideshow":{"slide_type":"fragment"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"auto array{ 1, 2, 3, 4, 5 };","metadata":{"slideshow":{"slide_type":"fragment"}},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"

              Quiz: char* argv[]

              \n

              What is char* argv[]?

              \n\n

              Example use case:

              ","metadata":{"slideshow":{"slide_type":"subslide"}}},{"cell_type":"code","source":"main(int argc, char* argv[]) {\n for (int i=0; i\n \n \n \n\n\n\n

              Dynamic arrays

              \n
                \n
              • Definition and allocation of dynamic array\n

                int* array = new int[5];

                \n
              • \n
              • Definition, allocation and initialisation of dynamic array\n

                int* array = new int[5]{ 1, 2, 3, 4, 5 }; // in C++11

                \n
              • \n
              • Explicit deallocation of dynamically allocated array needed\n

                delete[] array;

                \n
              • \n
              • Think fail-safe! Because it still points to an invalid address\n

                array = nullptr;

                \n
              • \n
              \n\n","metadata":{"slideshow":{"slide_type":"slide"}}},{"cell_type":"markdown","source":"

              Dynamic arrays

              ","metadata":{"slideshow":{"slide_type":"subslide"}}},{"cell_type":"code","source":"#include \nint* array = new int[5]{ 1, 2, 3, 4, 5 };\nfor (auto i=0; i<5; i++)\n std::cout << array[i] << std::endl;\ndelete[] array;\narray = nullptr;","metadata":{"tags":[],"slideshow":{"slide_type":"fragment"},"trusted":true},"execution_count":5,"outputs":[{"name":"stdout","text":"1\n2\n3\n4\n5\n","output_type":"stream"}]},{"cell_type":"code","source":"","metadata":{"trusted":true,"tags":[]},"execution_count":6,"outputs":[{"name":"stderr","text":"Unknown magic cell function %%html\n","output_type":"stream"}]},{"cell_type":"code","source":"\n\n","metadata":{"trusted":true,"tags":[]},"execution_count":1,"outputs":[{"name":"stderr","text":"Unknown magic cell function %%html\n","output_type":"stream"}]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]} \ No newline at end of file diff --git a/notebooks/static/plots/lecture2_abstract_classes.png b/notebooks/static/plots/lecture2_abstract_classes.png new file mode 100644 index 0000000..a497565 Binary files /dev/null and b/notebooks/static/plots/lecture2_abstract_classes.png differ diff --git a/notebooks/static/plots/lecture2_gaussrule.png b/notebooks/static/plots/lecture2_gaussrule.png new file mode 100644 index 0000000..ddb53ad Binary files /dev/null and b/notebooks/static/plots/lecture2_gaussrule.png differ diff --git a/notebooks/static/plots/lecture2_program_design.png b/notebooks/static/plots/lecture2_program_design.png new file mode 100644 index 0000000..13c63d3 Binary files /dev/null and b/notebooks/static/plots/lecture2_program_design.png differ diff --git a/notebooks/static/plots/lecture2_program_design_02.png b/notebooks/static/plots/lecture2_program_design_02.png new file mode 100644 index 0000000..bc87be6 Binary files /dev/null and b/notebooks/static/plots/lecture2_program_design_02.png differ diff --git a/notebooks/static/plots/lecture2_program_design_03.png b/notebooks/static/plots/lecture2_program_design_03.png new file mode 100644 index 0000000..3d477e9 Binary files /dev/null and b/notebooks/static/plots/lecture2_program_design_03.png differ diff --git a/notebooks/static/plots/lecture3_StaticPolyRoT.png b/notebooks/static/plots/lecture3_StaticPolyRoT.png new file mode 100644 index 0000000..fc762e1 Binary files /dev/null and b/notebooks/static/plots/lecture3_StaticPolyRoT.png differ diff --git a/notebooks/static/plots/lecture3_overloadingvsoverriding.png b/notebooks/static/plots/lecture3_overloadingvsoverriding.png new file mode 100644 index 0000000..dd15d8e Binary files /dev/null and b/notebooks/static/plots/lecture3_overloadingvsoverriding.png differ diff --git a/notebooks/static/plots/lecture3cat.gif b/notebooks/static/plots/lecture3cat.gif new file mode 100644 index 0000000..b42b4b6 Binary files /dev/null and b/notebooks/static/plots/lecture3cat.gif differ diff --git a/notebooks/static/plots/lecture4_cat.png b/notebooks/static/plots/lecture4_cat.png new file mode 100644 index 0000000..4a3bb59 Binary files /dev/null and b/notebooks/static/plots/lecture4_cat.png differ diff --git a/notebooks/static/plots/object_lego.png b/notebooks/static/plots/object_lego.png new file mode 100644 index 0000000..08bd8c5 Binary files /dev/null and b/notebooks/static/plots/object_lego.png differ diff --git a/notebooks/static/plots/paymentmethod1.png b/notebooks/static/plots/paymentmethod1.png new file mode 100644 index 0000000..2980313 Binary files /dev/null and b/notebooks/static/plots/paymentmethod1.png differ diff --git a/notebooks/static/plots/paymentmethod2.png b/notebooks/static/plots/paymentmethod2.png new file mode 100644 index 0000000..9cfbbd7 Binary files /dev/null and b/notebooks/static/plots/paymentmethod2.png differ diff --git a/notebooks/static/plots/pythonprocon.png b/notebooks/static/plots/pythonprocon.png new file mode 100644 index 0000000..5732f10 Binary files /dev/null and b/notebooks/static/plots/pythonprocon.png differ diff --git a/notebooks/static/plots/squarewheelcar.png b/notebooks/static/plots/squarewheelcar.png new file mode 100644 index 0000000..fe5eef5 Binary files /dev/null and b/notebooks/static/plots/squarewheelcar.png differ