pjobro

day 4 svasta

Mar 13th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. pokazivac............
  2. int main()
  3. {
  4.     int x = 8;
  5.     int *p_x = nullptr;
  6.     p_x = &x;
  7.  
  8.     cout << "x= " << x << endl;
  9.     cout << "p_x= " << p_x << endl;
  10.     cout << "&x= " << &x << endl;
  11.     cout << "*p_x= " << *p_x << endl;
  12.     return 0;
  13. }
  14. dina alokacija sa prezentacije......
  15. int main()
  16. {
  17.     int *p_x = new int;
  18.     *p_x = 10;
  19.     cout << "na adresi " << p_x << "upisana je vrijednost " << *p_x << endl;
  20.  
  21.     delete p_x;
  22.     p_x = nullptr;
  23.     return 0;
  24. }
  25. ......
  26. int main()
  27. {
  28.     int x;
  29.     cout << "unesite velicinu: ";
  30.     cin >> x;
  31.  
  32.     int *polje = new int[x];
  33.  
  34.     for (int i = 0; i < x; i++) {
  35.         cout << "polje " << i << ": ";
  36.         cin >> polje[i];
  37.  
  38.     }
  39.     for (int i = 0; i < x; i++)
  40.     {
  41.         cout <<polje[i] << "\t";
  42.     }
  43.     delete polje;
  44.     polje = nullptr;
  45.  
  46.     return 0;
  47.  
  48. }
  49. vektori......zadatak 1 iz prezentacije..
  50. int main()
  51. {
  52.     vector <int> vektor;
  53.     int unos = 0;
  54.     do {
  55.         cout << "unestie element u vektor: ";
  56.         cin >> unos;
  57.         vektor.push_back(unos);
  58.     } while (unos != 0);
  59.     for (int i = 0; i < vektor.size(); i++) {
  60.         cout << "element vektora na poziciji" << i << "je: " << vektor[i] << endl;
  61.     }
  62.     cout << endl;
  63.  
  64.     return 0;
  65. }
Add Comment
Please, Sign In to add comment