--- title: "2D Arrays in Small-C" type: "article" slug: "2d-arrays-in-small-c" url: "http://localhost/article/2d-arrays-in-small-c/" markdown_url: "http://localhost/article/2d-arrays-in-small-c.md" published_at: "2025-11-21T19:09:00+00:00" modified_at: "2026-06-21T23:36:46+00:00" featured_image: url: "http://localhost/wp-content/uploads/2022/04/20230809-041332.jpg" excerpt: "In a recent article in The C Users Journal, Don Lang discusses how to implement 2D arrays on C. His article covers code that when added to the original Small-C source, allows Small-C to support 2D arrays. Since the source code for the QL's Small-C compiler is not available, we could not use the code…" category: - name: "QL Hacker's Journal" slug: "ql-hackers-journal" taxonomy: "category" url: "http://localhost/category/periodicals/ql-hackers-journal/" post_tag: - name: "C (programming language)" slug: "c-programming-language" taxonomy: "post_tag" url: "http://localhost/tag/c-programming-language/" - name: "Full Text" slug: "fulltext" taxonomy: "post_tag" url: "http://localhost/tag/fulltext/" - name: "QL" slug: "ql" taxonomy: "post_tag" url: "http://localhost/tag/ql/" - name: "Type-in program" slug: "type-in-program" taxonomy: "post_tag" url: "http://localhost/tag/type-in-program/" model: - name: "Sinclair QL" slug: "sinclair-ql" taxonomy: "model" url: "http://localhost/model/sinclair-ql/" indiv: - name: "Tim Swenson" slug: "tim-swenson" taxonomy: "indiv" url: "http://localhost/indiv/tim-swenson/" publication_r: id: 33686 title: "QL Hacker’s Journal" type: "periodical" url: "http://localhost/periodical/ql-hackers-journal/" authors_r: - name: "Tim Swenson" slug: "tim-swenson" taxonomy: "indiv" url: "http://localhost/indiv/tim-swenson/" issue: "5" issues_articles: - id: 61541 title: "QL Hacker’s Journal 5" type: "issue" url: "http://localhost/issue/ql-hackers-journal-4-2/" pubdate: "August 1991" archive_link: true --- In a recent article in The C Users Journal, Don Lang discusses how to implement 2D arrays on C. His article covers code that when added to the original Small-C source, allows Small-C to support 2D arrays. Since the source code for the QL’s Small-C compiler is not available, we could not use the code he provides. But he does discuss a not-so-elegant way of implementing 2D arrays. Since memory is really a 1D array, the computer figures out where in memory an element of an array is. This can be easily done in Small-C. Given an array of size MAX_X, and elements starting at 0, then (x,y) is equal to (( x * MAX_X ) + y). Below is a sample Small-C program that demonstrates this: ``` /* Two Dimensional Arrays in Small-C For an array of [10][5] let MAX_X = 10 Assumptions: Arrays start at 0. For an array of size 10, range is 0..9. Way to address the cell at x,y: temp = array[(x*MAX_X)+y]; */ #define MAX_X 10 main() { int array[100]; /* 10x10 array */ int x,y; for (x = 0; x <= 9; x++) { for (y = 0; y <= 9; y++) { array[(x*MAX_X)+y] = x*y; printf("%d ",array[(x*MAX_X)+y]); } printf("\n"); } } ```