Functions in C++ Part I
Today we talked about a couple important things in C++, including the const keyword, why you shouldn't use floats in general circumstances, and the difference between the core C++ language and the standard library (code which comes with most every distribution of C++). We explored the standard library a bit and learned how to look up what header file things are in, and why you may or may not want to use bits/stdc++.h in your includes (compile time goes up).
But the big topic for today was the topic of functions. At the most basic level, they work like functions do in algebra. You pass in some parameters and get a result back out. (We'll talk next time about functions without parameters or return values.) For example, the abs() function takes in a number and returns the distance that number is from 0 (i.e. makes negative numbers positive).
You can make a function in C++ up above main by following this pattern:
return_type function_name(parameter list) { code; }
For example, if you wanted to write a function that squared a number you could do it something like this:
double square(double x) {
return x*x;
}
Other Videos By Bill Kerney
2021-09-11 | Call by Reference |
2021-09-10 | Modus Ponens and Modus Tollens |
2021-09-10 | SVN, Voronoi |
2021-09-10 | GDC Talks, Landscape III, Material Functions |
2021-09-10 | Combinatorics, Inclusion/Exclusion |
2021-09-08 | Functions Part II |
2021-09-08 | Arguments + Invalid/Valid/Sound |
2021-09-07 | Voroni |
2021-09-07 | CSG, Sprinting, Water (Old and New) |
2021-09-07 | Constexpr, Permutations, Combinations, Binomial Theorem, and Infinite Sets |
2021-09-03 | Functions in C++ Part I |
2021-09-03 | Five Theories of Truth |
2021-09-02 | UE4 Blueprints |
2021-09-02 | Set Theory I |
2021-09-02 | The Laser Zombies |
2021-09-01 | Integer Overflow, String Comparisons, Range-Based For Loops, Nested Loops |
2021-09-01 | Truth Part 1 |
2021-09-01 | Landscapes Part I |
2021-09-01 | Project Updates |
2021-08-31 | Hash Tables + Counting |
2021-08-30 | Coding with Loops |