[课程相关]homework-08

一、变量作用域和生命周期

 1 #include <cstdlib>
 2 #include <iostream>  
 3 
 4 using namespace std;
 5 
 6 void try_change(int a){
 7     a = 20;
 8 }
 9 
10 int main(int argc, char** argv) {
11     int a = 10;
12     try_change(a);
13     cout<<a;
14     return 0;
15 }

二、堆和栈

 1 #include <cstdlib>
 2 #include <iostream>  
 3 
 4 using namespace std;
 5 
 6 int *a;
 7 int *d;
 8 
 9 void try_both(){
10     int *b = new int(100);
11     int c = 200;
12     a = b;
13     d = &c;
14 }
15 
16 
17 int main(int argc, char** argv) { 
18     try_both();
19     cout<<*a<<endl;
20     cout<<*d<<endl;
21     return 0;
22 }

三、分解url

为什么我要用Python写:

  1. 我不喜欢c++
  2. 我喜欢Python
  3. 这门课是“现代程序设计”而不是“现代C++设计”,所以我认为可以选择自己喜欢的语言
1 flat=lambda L: sum(map(flat,L),[]) if isinstance(L,list) else [L]
2 print ', '.join(flat([flat([j.split('.') for j in flat([i.split('/') for i in raw_input("Please enter the url:").split("://")])])]))
原文地址:https://www.cnblogs.com/numbbbbb/p/3426443.html