Skip to content

Commit

Permalink
update: 增加材料
Browse files Browse the repository at this point in the history
Signed-off-by: YdrMaster <[email protected]>
  • Loading branch information
YdrMaster committed Jul 23, 2024
1 parent 3912fbf commit 3f59af9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions exercises/02_function/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "../exercise.h"

// READ: 声明 <https://zh.cppreference.com/w/cpp/language/declarations>
// NOTICE: cppreference 中的示例中指出了复杂声明的解读法,建议认真阅读。
// NOTICE: 补充由内而外读法的机翻解释 <https://learn.microsoft.com/zh-cn/cpp/c-language/interpreting-more-complex-declarators?view=msvc-170>

// TODO: 在这里声明函数

int main(int argc, char **argv) {
Expand Down
5 changes: 3 additions & 2 deletions exercises/03_argument&parameter/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// READ: <https://stackoverflow.com/questions/156767/whats-the-difference-between-an-argument-and-a-parameter>

#include "../exercise.h"

// READ: <https://stackoverflow.com/questions/156767/whats-the-difference-between-an-argument-and-a-parameter>
// THINK: 参数都有哪些传递方式?如何选择传递方式?

void func(int);

// TODO: 为下列 ASSERT 填写正确的值
Expand Down
1 change: 1 addition & 0 deletions exercises/05_constexpr/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ int main(int argc, char **argv) {
std::cout << "fibonacci(20) = " << FIB20 << std::endl;

// TODO: 观察错误信息,修改一处,使代码编译运行
// PS: 编译运行,但是不一定能算出结果……
constexpr auto ANS_N = 90;
constexpr auto ANS = fibonacci(ANS_N);
std::cout << "fibonacci(" << ANS_N << ") = " << ANS << std::endl;
Expand Down
2 changes: 2 additions & 0 deletions exercises/06_loop/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "../exercise.h"

// TODO: 改正函数实现,实现正确的缓存优化斐波那契计算
// THINk: 这个函数是一个纯函数(pure function)吗?
// READ: 纯函数 <https://zh.wikipedia.org/wiki/%E7%BA%AF%E5%87%BD%E6%95%B0>
static unsigned long long fibonacci(int i) {
// TODO: 为缓存设置正确的初始值
static unsigned long long cache[96], cached;
Expand Down
5 changes: 4 additions & 1 deletion exercises/07_enum&union/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ enum class Color : int {
};

ColorEnum convert_by_pun(Color c) {
// READ: <https://zh.cppreference.com/w/cpp/language/union>
// `union` 表示在同一内存位置存储的不同类型的值。
// 其常见用法是实现类型双关转换,即将一种类型的值转换为另一种无关类型的值。
// READ: <https://zh.cppreference.com/w/cpp/language/union>
// 但这种写法实际上仅在 C 语言良定义,在 C++ 中是未定义行为。
// 这是比较少见的 C++ 不与 C 保持兼容的特性。
// READ: 类型双关 <https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html>
union TypePun {
ColorEnum e;
Color c;
Expand Down

0 comments on commit 3f59af9

Please sign in to comment.