forked from LearningInfiniTensor/learning-cxx
-
Notifications
You must be signed in to change notification settings - Fork 428
Expand file tree
/
Copy pathmain.cpp
More file actions
20 lines (18 loc) · 801 Bytes
/
main.cpp
File metadata and controls
20 lines (18 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "../exercise.h"
// READ: `static` 关键字 <https://zh.cppreference.com/w/cpp/language/storage_duration>
// THINK: 这个函数的两个 `static` 各自的作用是什么?
static int func(int param) {
static int static_ = param;
// std::cout << "static_ = " << static_ << std::endl;
return static_++;
}
int main(int argc, char **argv) {
// TODO: 将下列 `?` 替换为正确的数字
ASSERT(func(5) ==5, "static variable value incorrect");
ASSERT(func(4) ==6, "static variable value incorrect");
ASSERT(func(3) ==7, "static variable value incorrect");
ASSERT(func(2) ==8, "static variable value incorrect");
ASSERT(func(1) ==9, "static variable value incorrect");
return 0;
}
/*static关键字作用:静态的,指定变量只初始化一次*/