Matrix, pointers, C*

后端 未结 3 2041
日久生厌
日久生厌 2021-01-25 00:53

I have code like this:

void print_matrix(int **a, int n) {
    int i, j;
    for(i = 0; i < n; i++) {
        for(j = 0; j < n; j++)
            printf(\"%         


        
3条回答
  •  北海茫月
    2021-01-25 01:22

    If you want n to vary (and be square), it is best to allocate and use a single dimension array and multiply when you want a different row.

    int matrix[3*3];
    

    How to use it?

    matrix[row*3+col] = 5;
    

    How to pass it.

    f(int *a,int n)
    

提交回复
热议问题