fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int *ShiftElements(int *array, int& size);
  5. int main()
  6. {
  7. int size;
  8. int array[size];
  9.  
  10. cout << "Enter size of array:" << endl;
  11. cin >> size;
  12.  
  13. cout << "enter " << size << " elements:" << endl;
  14. for(int count = 0; count < size; count++)
  15. cin >> *(array + count);
  16.  
  17. int *shifted = ShiftElements(array, size);
  18.  
  19. cout << "Updated Array is:" << endl;
  20. for(int count = 0; count < size; count++)
  21. {
  22. cout << *(shifted + count) << " ";
  23. }
  24.  
  25. delete[] shifted;
  26.  
  27. return 0;
  28. }
  29.  
  30. int *ShiftElements(int *array, int& size)
  31. {
  32.  
  33. size += 1;
  34. int *shifted = new int [size];
  35.  
  36. *(shifted + 0) = 0;
  37.  
  38. for(int count = 0; count < size - 1; count++)
  39. *(shifted + (count + 1)) = *(array + count);
  40.  
  41. return shifted;
  42. }
Success #stdin #stdout 0.01s 5288KB
stdin
3
1
2
3
stdout
Enter size of array:
enter 3 elements:
Updated Array is:
0  1  2  3