fork(1) download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. #define SIZE (1)
  6. struct arry
  7. {
  8. int *n = NULL;
  9. int size;
  10. arry() { n = new int[SIZE]; size = SIZE; }
  11. ~arry() { delete [] n; }
  12. void incSize() {
  13. int *temp = new int[size + 1];
  14. memcpy(temp, n, sizeof(int) * size);
  15. delete [] n;
  16. n = temp;
  17. size++;
  18. }
  19. };
  20.  
  21. int main() {
  22.  
  23. arry dyn;
  24.  
  25. dyn.n[0] = 100;
  26.  
  27. cout << sizeof dyn.n << endl;
  28. cout << dyn.size << endl;
  29.  
  30. dyn.incSize();
  31.  
  32. cout << sizeof dyn.n << endl;
  33. cout << dyn.size << endl;
  34.  
  35. dyn.n[1] = 200;
  36.  
  37. cout << dyn.n[0] << endl;
  38. cout << dyn.n[1] << endl;
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
4
1
4
2
100
200