fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // array(static memoru allocation)(fixed memory get allocated at compile time)(after exection of program , static memory gets deallocated)
  6. // int arr[]={1,2,3,4,5,6,7,8,9};
  7. // for(int i=0;i<10;i++){
  8. // cout<<*(arr+i)<<" --> "<<(arr+i)<<endl;
  9.  
  10. // }
  11.  
  12. // int ok[1]={10,20,30};
  13. // cout<<ok;
  14.  
  15. // int ok[15]={};
  16. // cout<<ok[4];
  17.  
  18. // int x; cin>>x;
  19. // int arr[x];
  20. // for(int i=0;i<x;i++){
  21. // // cin>>x;
  22. // // arr[i]=x;
  23. // cin>>arr[i];
  24. // cout<<arr[i]<<endl;
  25. // }
  26.  
  27. //vector(dynamic array)(memory get allocated in runtime)(dellocated memory manually after execution of code)
  28. vector<int> v={1,2,3,4,5};
  29. vector<int> ok(5,6); // vector of size 5 with each value initialised with 6
  30. // cout<<ok[2]<<endl;
  31. cout<<ok.size()<<endl; // return size of vector
  32. cout<<ok.capacity()<<endl;
  33. cout<<v.front()<<" "<<v.back()<<endl; //v.front()=> v[0] v.back()=> last element of vector
  34. v.push_back(89); // insert element from last
  35. v.push_back(589);
  36. ok.push_back(8888);
  37. ok.push_back(888);
  38. ok.push_back(88);
  39. ok.push_back(8);
  40. cout<<ok.front()<<" "<<ok.back()<<endl;
  41. cout<<"ok size- "<<ok.size()<<endl;
  42. v.insert(v.begin()+3,8969); // 1 2 3 8969 4 5
  43. v.erase(v.begin()+3); // 1 2 3 4 5
  44. cout<<v[3]<<endl;
  45.  
  46. // int* arr=new int[5]; //heap memory allocation(whenever element is stored in heap we use pointer to extract it)
  47. // for(int i=0;i<5;i++){
  48. // cout<<arr+i<<endl;
  49. // cout<<*(arr+i)<<endl; // all element is intialised with 0
  50.  
  51. // }
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. return 0;
  62. }
Success #stdin #stdout 0s 5320KB
stdin
5
0 1 2 3 4
stdout
5
5
1  5
6  8
ok size- 9
4