c++ – Passing two dimensional array by reference c ++


There is a two-dimensional array of numbers. Int mass [15] [20] You need to pass it to the function so that changing it in the function is reflected in main. After trying to figure it out, I realized that I needed to somehow transfer it by reference, but I can't figure out how.


Submit. Just don't forget the parentheses:

#include <iostream>

void f(int (& mass)[15][20]) {
  mass[1][1] = 42;

int main() {
  int mass[15][20] = { 0 };
  std::cout << mass[1][1] << std::endl;
  return 0;
Scroll to Top