fork download
  1. #include <iostream>
  2.  
  3. void foo(int array[], const size_t arraySize)
  4. {
  5. // you can either use pointer arithmetic directly like this
  6. for(size_t i = 0; i != arraySize; ++i)
  7. {
  8. std::cout << *(array + i) << ' ';
  9. }
  10.  
  11. std::cout << '\n';
  12.  
  13. // or you can just use the index operator as normal
  14. for(size_t i = 0; i != arraySize; ++i)
  15. {
  16. std::cout << array[i] << ' ';
  17. }
  18.  
  19. std::cout << std::endl;
  20. }
  21.  
  22. int main()
  23. {
  24. const size_t arraySize = 8;
  25. int myArray[arraySize] = {
  26. 0, 1, 2, 3, 4, 5, 6, 7
  27. };
  28.  
  29. foo(myArray, arraySize);
  30. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
0 1 2 3 4 5 6 7 
0 1 2 3 4 5 6 7