2

In the directive #define you can define a static array, but I couldn't understand how you can define a static matrix?. I would like to create a library of static matrices.

Can anyone help me?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
ginosal
  • 35
  • 1
  • 1
  • 6
  • 2
    Please check the [FAQ - How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) on how to ask good questions, so that you get good answers. At least, you should have tried something yourself, and ideally show some **code** of what you have tried. In particular, you are **not** usually using `#define` to define static arrays. Please show what you want to achieve (at least in pseudo code) – Andreas Fester Jul 24 '14 at 07:10

1 Answers1

7

I'd guess you want to use it like follows :

#include <stdio.h>
#include <string.h>

const int matrix[3][4]=
{
    {1, 5, 6, 7},
    {4, 4, 8, 0},
    {2, 3, 4, 5}
};

int main()
{
    int i, j;
    for(i = 0; i< 3; i++)
    {
        for(j = 0; j<4; j++)
        {
            printf("%d ", matrix[i][j]);
        }
        printf("\n");
    }
}
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
chouaib
  • 2,763
  • 5
  • 20
  • 35