D3ad

2D array as 1D array

Mar 28th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. typedef struct{
  2.     int x;
  3.     int y;
  4. }point_t;
  5.  
  6. int main(){
  7.     int width = 5;
  8.     int height = 4;
  9.     /* velikost 2D pole */
  10.     int size = width * height;
  11.     /* 1D pole o velikosti 2D pole a vynuluju */
  12.     point_t array[size];
  13.     memset(&array, 0, sizeof(SIZE_OF_MATRIX));
  14.     /* pristupujeme k prvku na radku X a ve sloupci Y pristupujeme stylem:
  15.      * array[ width * X + Y]; indexujem od nuly */
  16. }
Add Comment
Please, Sign In to add comment