Language: C++

#include <iostream>

void change(int *a)
{
  if(*a ==1){
  	*a = 0;
  }
  else if(*a == 0)
  {
    *a=1;
  }
    
}

int main(void)
{
	int M,N;
  	std::cin >> N;
  	std::cin >> M;
  	int answer;
  	int mat[N][M];
 	
  	for(int i=0;i<N;i++)
    {
      for(int j=0;j<M;j++){
      	mat[i][j] = 0;
      }
    }
  
  for(int i=0;i<N;i++)
    {
      for(int j=0;j<M;j++){
        if(i-1>0 && j-1>0){
      	change(mat[i-1][j-1]);
        }
        if(j-1>0){
        change(mat[i][j-1]);
        }
          if(j-1>0 && i+1<N){
        change(mat[i+1][j-1]);
          }
            if(i-1>0){
        change(mat[i-1][j]);
            }        
        change(mat[i][j]);
        if(i+1<N){
        change(mat[i+1][j]);
        }
          if(i-1>0 && j+1<M){
        change(mat[i-1][j+1]);
          }
            if(j+1<M){
        change(mat[i][j+1]);
            }
        if(i+1<N && j+1<M){
        change(mat[i+1][j+1]);
        }
        
      }
    }
  
    for(int i=0;i<N;i++)
    {
      for(int j=0;j<M;j++){
      	if(mat[i][j] == 1){
        	answer++;
        }
      }
    }
    
    std::cout << answer << std::endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:34:28: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   34 |         change(mat[i-1][j-1]);
      |                ~~~~~~~~~~~~^
      |                            |
      |                            int
a.cc:3:18: note:   initializing argument 1 of 'void change(int*)'
    3 | void change(int *a)
      |             ~~~~~^
a.cc:37:26: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   37 |         change(mat[i][j-1]);
      |                ~~~~~~~~~~^
      |                          |
      |                          int
a.cc:3:18: note:   initializing argument 1 of 'void change(int*)'
    3 | void change(int *a)
      |             ~~~~~^
a.cc:40:28: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   40 |         change(mat[i+1][j-1]);
      |                ~~~~~~~~~~~~^
      |                            |
      |                            int
a.cc:3:18: note:   initializing argument 1 of 'void change(int*)'
    3 | void change(int *a)
      |             ~~~~~^
a.cc:43:26: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   43 |         change(mat[i-1][j]);
      |                ~~~~~~~~~~^
      |                          |
      |                          int
a.cc:3:18: note:   initializing argument 1 of 'void change(int*)'
    3 | void change(int *a)
      |             ~~~~~^
a.cc:45:24: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   45 |         change(mat[i][j]);
      |                ~~~~~~~~^
      |                        |
      |                        int
a.cc:3:18: note:   initializing argument 1 of 'void change(int*)'
    3 | void change(int *a)
      |             ~~~~~^
a.cc:47:26: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   47 |         change(mat[i+1][j]);
      |                ~~~~~~~~~~^
      |                          |
      |                          int
a.cc:3:18: note:   initializing argument 1 of 'void change(int*)'
    3 | void change(int *a)
      |             ~~~~~^
a.cc:50:28: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   50 |         change(mat[i-1][j+1]);
      |                ~~~~~~~~~~~~^
      |                            |
      |                            int
a.cc:3:18: note:   initializing argument 1 of 'void change(int*)'
    3 | void change(int *a)
      |             ~~~~~^
a.cc:53:26: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   53 |         change(mat[i][j+1]);
      |                ~~~~~~~~~~^
      |                          |
      |                          int
a.cc:3:18: note:   initializing argument 1 of 'void change(int*)'
    3 | void change(int *a)
      |             ~~~~~^
a.cc:56:28: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   56 |         change(mat[i+1][j+1]);
      |                ~~~~~~~~~~~~^
      |                            |
      |                            int
a.cc:3:18: note:   initializing argument 1 of 'void change(int*)'
    3 | void change(int *a)
      |             ~~~~~^