program_6_4.cpp
来自「清华关于C++ 的程序讲义 值得一看 关于算法」· C++ 代码 · 共 39 行
CPP
39 行
// program 6.4: local scope
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main() {
cout << "5 random numbers from 0 to 99:" << endl;
srand( (unsigned int) time(0) );
for ( int i=1; i<=5; ++i ) {
cout << rand()%100 << endl;
}
// print i
cout << "scope testing: i = " << i << endl;
return 0;
}
// another example
#include <iostream>
using namespace std;
void Mystery(int a, int b); // prototype
int main() {
int i = 10;
int j = 20;
Mystery(i, j);
cout << a << endl;
cout << b << endl;
return 0;
}
void Mystery(int a, int b) {
cout << a << endl;
cout << b << endl;
a = 1;
b = 2;
cout << a << endl;
cout << b << endl;
return;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?