{"id":7111,"date":"2020-07-17T17:59:50","date_gmt":"2020-07-18T00:59:50","guid":{"rendered":"https:\/\/zxi.mytechroad.com\/blog\/?p=7111"},"modified":"2020-07-17T18:00:46","modified_gmt":"2020-07-18T01:00:46","slug":"why-gridyx-instead-of-gridxy","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/cs\/why-gridyx-instead-of-gridxy\/","title":{"rendered":"Why grid[y][x] instead of grid[x][y]?"},"content":{"rendered":"\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Why grid[y][x] instead of grid[x][y]? - CS\u5927\u8bb2\u5802 EP16\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/P50r4CDeUYw?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"960\" height=\"540\" src=\"https:\/\/zxi.mytechroad.com\/blog\/wp-content\/uploads\/2020\/07\/grid_y_x-ep16-1.png\" alt=\"\" class=\"wp-image-7112\" srcset=\"https:\/\/zxi.mytechroad.com\/blog\/wp-content\/uploads\/2020\/07\/grid_y_x-ep16-1.png 960w, https:\/\/zxi.mytechroad.com\/blog\/wp-content\/uploads\/2020\/07\/grid_y_x-ep16-1-300x169.png 300w, https:\/\/zxi.mytechroad.com\/blog\/wp-content\/uploads\/2020\/07\/grid_y_x-ep16-1-768x432.png 768w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"960\" height=\"540\" src=\"https:\/\/zxi.mytechroad.com\/blog\/wp-content\/uploads\/2020\/07\/grid_y_x-ep16-2.png\" alt=\"\" class=\"wp-image-7113\" srcset=\"https:\/\/zxi.mytechroad.com\/blog\/wp-content\/uploads\/2020\/07\/grid_y_x-ep16-2.png 960w, https:\/\/zxi.mytechroad.com\/blog\/wp-content\/uploads\/2020\/07\/grid_y_x-ep16-2-300x169.png 300w, https:\/\/zxi.mytechroad.com\/blog\/wp-content\/uploads\/2020\/07\/grid_y_x-ep16-2-768x432.png 768w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/figure>\n\n\n\n<p>If you don&#8217;t like grid[y][x], you can use grid[r][c] instead.<\/p>\n\n\n\n<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">C++<\/h2>\n<div class=\"tabcontent\">\n\n<pre lang=\"c++\">\n#include <iostream>\n\nusing namespace std;\n\nint main(int argc, char** argv) {\n  constexpr int kRows = 2;\n  constexpr int kCols = 3;\n  int arr[kRows][kCols] = {{1,2,3},{4,5,6}};\n  for (int r = 0; r < kRows; ++r) {\n    for (int c = 0; c < kCols; ++c)\n      cout << arr[r][c] << \" \";\n    cout << endl;\n  }\n\n  for (int r = 0; r < kRows; ++r)\n    for (int c = 0; c < kCols; ++c)\n      cout << &#038;(arr[r][c]) - &#038;(arr[0][0]) << \" \";\n  return 0;\n}\n\n\/\/ Output:\n\/\/ 1 2 3\n\/\/ 4 5 6\n\/\/ 0 1 2 3 4 5\n<\/pre>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>If you don&#8217;t like grid[y][x], you can use grid[r][c] instead. #include using namespace std; int main(int argc, char** argv) { constexpr int kRows = 2;&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[452],"tags":[633,631,634,632],"class_list":["post-7111","post","type-post","status-publish","format-standard","hentry","category-cs","tag-column-major","tag-cs","tag-memory","tag-row-major","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/7111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=7111"}],"version-history":[{"count":2,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/7111\/revisions"}],"predecessor-version":[{"id":7115,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/7111\/revisions\/7115"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=7111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=7111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=7111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}