Error: invalid conversion from 'int' to 'int * (*) [4]' [- fpermisive] C ++

1

I have to make a 4x4 matrix, then load the main diagonal with zeros and show it, so that finally I count the multiples of 5 in it. I want to send the matrix by reference , in order to modify the original from the diagonalpp function. It is important to note that no I am allowed to declare global variables . I throw this error and I have tried many things and I can not solve it.

#include<stdio.h>
#include<time.h>
#include<stdlib.h>


void diagonalPP (int* m[][4]);
int multiplos (int* m[][4]);

int main()
{
    int f,c,mul, m[4][4];

    for (f=0;f<4;f++) 
    {
        for (c=0;c<4;c++) 
        {
            scanf("%d",& m[f][c]);

        }       
    }
    for (f=0;f<4;f++) 
    {
        for (c=0;c<4;c++) 
        {
            printf("%d", m[f][c]);
            printf("\t");
        }

        printf("\n");
    }

    diagonalPP (m[4][4]);

        for (f=0;f<4;f++) 
    {
            for (c=0;c<4;c++) 
            {
                printf("%d", m[f][c]);
                printf("\t");
            }

            printf("\n");
    }

    mul= multiplos (m);

        printf("La cantidad de multiplos de 5 es:%d",mul);

}

void diagonalPP (int* m[][4])
{
    for (int f=0;f<4;f++) 
    {
        for (int c=0;c<4;c++) 
        {
            if (f==c)
            {
                *m[f][c]=0;
            }
        }
    }
}

int multiplos (int* m[][4])
{
    int cont=0;
    for (int f=0;f<4;f++) 
    {
        for (int c=0;c<4;c++) 
        {
            if (m[f][c]%5==0)
            {
                cont ++;
            }
        }
    }   
    return cont;


}
    
asked by Frio Bajo Cero 01.12.2018 в 15:19
source

2 answers

1

The parameter you use when calling the diagonal method is not correct. With what you put only you pass a value, and you want to pass the whole matrix. Simply pass m, which is already passed by reference. Neither the definition of the diagonal method nor the multiplos method is correct. I have also made a correction in the multiples method, to avoid telling you that the 0 is a multiple of 5. I put here the resulting code

    #include <stdio.h>

    void diagonalPP (int m[4][4]); 
    int multiplos (int m[4][4]);
    int main() { int f,c,mul, m[4][4];
    for (f=0;f<4;f++) 
    {
        for (c=0;c<4;c++) 
        {
            scanf("%d",& m[f][c]);

        }       
    }
    for (f=0;f<4;f++) 
    {
        for (c=0;c<4;c++) 
        {
            printf("%d", m[f][c]);
            printf("\t");
        }

        printf("\n");
    }

    diagonalPP (m);

        for (f=0;f<4;f++) 
    {
            for (c=0;c<4;c++) 
            {
                printf("%d", m[f][c]);
                printf("\t");
            }

            printf("\n");
    }

    mul= multiplos (m);

        printf("La cantidad de multiplos de 5 es:%d",mul);
    }
 void diagonalPP (int m[4][4]) { 
  for (int f=0;f<4;f++) { 
      for (int c=0;c<4;c++) 
        { 
          if (f==c) { m[f][c]=0; } 
        } 
  }
 }
 int multiplos (int m[4][4]) 
 { 
   int cont=0; 
   for (int f=0;f<4;f++) 
   { 
     for (int c=0;c<4;c++) 
     {
       if ((m[f][c]!=0) && (m[f][c]%5==0)) 
       { cont ++; }
     } 
   }
   return cont;
 }
    
answered by 01.12.2018 / 16:32
source
1
  

I want to send the matrix by reference

Well you've been doing it wrong, this:

void diagonalPP (int* m[][4]);
int multiplos (int* m[][4]);

Do not pass the matrices by reference, what you're looking for is this:

void diagonalPP (int (&m)[4][4]);
int multiplos (int (&m)[4][4]);

If the syntax seems confusing, do not worry, you are not alone. Luckily you can use an alias to make things easier:

using m4x4 = int[4][4];

The type m4x4 is an array of four by four integers, so to pass a reference to that type of matrix, it's as easy as:

void diagonalPP (m4x4 &m);
int multiplos (m4x4 &m);
    
answered by 01.12.2018 в 16:39