fork(2) download
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5. int width = 4, height = 4;
  6.  
  7. int arr[width * height];
  8.  
  9. for (int i = 0, k = 0; i < height; ++i)
  10. {
  11. for (int j = 0; j < width; ++j)
  12. {
  13. arr[i * width + j] = k++;
  14. }
  15. }
  16.  
  17.  
  18.  
  19. for (int i = 0; i < height; ++i)
  20. {
  21. for (int j = 0; j < width; ++j)
  22. {
  23. int* ptr = &arr[0] + height * i;
  24. std::cout<<ptr[j]<<" ";
  25. }
  26. }
  27. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
0   1   2   3   4   5   6   7   8   9   10   11   12   13   14   15