返回列表 發帖

指標 (五) - 陣列 1

本帖最後由 tonyh 於 2014-9-13 18:03 編輯

陣列指標 --> 存放陣列成員位址的變數
位址運算符號 & --> 取得變數位址
間接運算符號 * --> 取得參考位址內的值
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.      int n[]={1,3,5,7,9};
  7.      int *nPtr;    //宣告指標 nPtr
  8.      nPtr=n;
  9.      //nPtr=&n[0];
  10.      cout<<*nPtr<<endl;
  11.      nPtr=&n[2];
  12.      cout<<*nPtr<<endl;
  13.      nPtr=&n[4];
  14.      cout<<*nPtr<<endl;
  15.      system("pause");
  16.      return 0;
  17. }
複製代碼

  1. #include <bits/stdc++.h>

  2. using namespace std;
  3. int mod = 1000000007, n;
  4. vector <int> dp;
  5. vector <int> coin;
  6. vector <int> visited;

  7. int aa(int x)
  8. {
  9.     if(visited[x])   return dp[x];
  10.     for(int i=0; i<n; i++)
  11.     {
  12.         if(coin[i]<=x)
  13.         {
  14.             dp[x] += aa(x-coin[i]);
  15.             dp[x]%=mod;
  16.         }
  17.     }
  18.     //cout << x << " " << dp[x] << endl;
  19.     visited[x]++;
  20.     return dp[x];
  21. }

  22. int main()
  23. {
  24.     /*
  25.     int x;
  26.     cin >> n >> x;
  27.     dp.resize(x);
  28.     visited.resize(x);
  29.     coin.resize(n);
  30.     dp[0]++;
  31.     visited[0]++;
  32.     for(int i=0; i<n; i++)
  33.         cin >> coin[i];
  34.     cout << aa(x);
  35.     return 0;
  36.     */
  37.     int n[] = {0, 1, 2, 3, 4, 5};
  38.     int *nptr = n;
  39.     cout << *nptr << endl;
  40.     nptr = &n[2];
  41.     cout << *nptr << endl;
  42.     nptr = &n[4];
  43.     cout << *nptr << endl;
  44. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.      
  7.      int n[]={1,3,5,7,9};
  8.      int* nPtr=n;
  9.      cout<<*nPtr<<endl;
  10.      nPtr=&n[2];
  11.      cout<<*nPtr<<endl;
  12.      nPtr=&n[4];
  13.      cout<<*nPtr<<endl;
  14.      system("pause");
  15.      return 0;
  16. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n[]={1,3,5,7,9};
  7.     int *nPtr;
  8.     nPtr=n;
  9.     cout<<*nPtr<<endl;
  10.     nPtr=&n[2];
  11.     cout<<*nPtr<<endl;
  12.     nPtr=&n[4];
  13.     cout<<*nPtr<<endl;
  14.     system("pause");
  15.     return 0;
  16. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.      int n[]={1,3,5,7,9};
  7.      int *nPtr;
  8.      nPtr=n;
  9.      cout<<*nPtr<<endl;
  10.      nPtr=&n[2];
  11.      cout<<*nPtr<<endl;
  12.      nPtr=&n[4];
  13.      cout<<*nPtr<<endl;
  14.      system("pause");
  15.      return 0;
  16. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n[]={1,3,5,7,9};
  7.     int *nPtr;
  8.     nPtr=n;
  9.     cout<<*nPtr<<endl;
  10.     nPtr=&n[2];
  11.     cout<<*nPtr<<endl;
  12.     nPtr=&n[4];
  13.     cout<<*nPtr<<endl;
  14.     system("pause");  
  15.     return 0;        
  16. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.     int n[]={1,3,5,7,9};
  8.     int *nPtr;
  9.     nPtr=n;
  10.     cout<<*nPtr<<endl;
  11.     nPtr=&n[2];
  12.     cout<<*nPtr<<endl;
  13.      nPtr=&n[4];
  14.     cout<<*nPtr<<endl;
  15.     system("pause");     
  16.     return 0;   
  17. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.     int n[]={1,3,5,7,9};
  7.     int *nPtr;
  8.     nPtr = n;
  9.     cout << *nPtr << endl;
  10.     nPtr = &n[2];
  11.     cout << *nPtr << endl;
  12.     nPtr = &n[4];
  13.     cout << *nPtr << endl;
  14.     system("pause");
  15.     return 0;
  16. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.      int n[]={1,3,5,7,9};
  7.      int *nPtr;
  8.      nPtr = n;
  9.      cout<<*nPtr<<endl;
  10.      nPtr = &n[2];
  11.      cout<<*nPtr<<endl;
  12.      nPtr = &n[4];
  13.      cout<<*nPtr<<endl;
  14.      
  15.      system("pause");
  16.      return 0;
  17. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n[]={1,3,5,7,9};
  7.     int *nPtr;
  8.     nPtr=n;
  9.     cout<<*nPtr<<endl;
  10.     nPtr=&n[2];
  11.     cout<<*nPtr<<endl;
  12.     nPtr=&n[4];
  13.     cout<<*nPtr<<endl;
  14.    
  15.     system("pause");   
  16.     return 0;
  17. }
複製代碼

TOP

返回列表