source: doc/theses/mike_brooks_MMath/tests/arrays.c

Last change on this file was b7f8cadb, checked in by Peter A. Buhr <pabuhr@…>, 4 months ago

add directory for non-CFA test programs

  • Property mode set to 100644
File size: 975 bytes
Line 
1#include <stdio.h>
2#include <malloc.h>
3
4void foo( int rows, int cols, int mp[rows][cols], int D1[5][5] ) {
5 for ( int r = 0; r < rows; r += 1 ) {
6 for ( int c = 0; c < rows; c += 1 ) {
7 printf( "%d ", mp[r][c] );
8 }
9 printf( "\n" );
10 }
11 for ( int r = 0; r < rows; r += 1 ) {
12 for ( int c = 0; c < rows; c += 1 ) {
13 printf( "%d ", D1[r][c] );
14 }
15 printf( "\n" );
16 }
17}
18void bar( int rows, int cols, int * mp[/* cols */] ) {
19 for ( int r = 0; r < rows; r += 1 ) {
20 for ( int c = 0; c < rows; c += 1 ) {
21 printf( "%d ", mp[r][c] );
22 }
23 printf( "\n" );
24 }
25}
26int main() {
27 int m[5][5]; // contiguous
28 int * aa[5]; // non-contiguous
29
30 int w[5];
31 for ( int r = 0; r < 5; r += 1 ) {
32 for ( int c = 0; c < 5; c += 1 ) {
33 m[r][c] = r + c;
34 }
35 }
36 foo( 5, 5, m, m );
37
38 printf( "\n" );
39
40 for ( int r = 0; r < 5; r += 1 ) {
41 aa[r] = (int *)malloc( 5 * sizeof(int) );
42 for ( int c = 0; c < 5; c += 1 ) {
43 aa[r][c] = r + c;
44 }
45 }
46 bar( 5, 5, aa );
47}
Note: See TracBrowser for help on using the repository browser.