int** array[i][j]
внутри функций, и как оно вообще работает?#include <iostream>
#include <Windows.h>
using std::cout;
using std::cin;
using std::endl;
void prog(int** a) {
int** g = a;
int** gg = a;
for (int i = 0; i < 3; ++i){
for (int j = 0; j < 3; ++j) {
cout << a[i][j] << " ";
}
cout << endl;
}
g[1][1] = 1;
cout << endl;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
cout << g[i][j] << " ";
}
cout << endl;
}
cout << endl;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
cout << gg[i][j] << " ";
}
cout << endl;
}
cout << endl;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
cout << a[i][j] << " ";
}
cout << endl;
}
}
int main() {
setlocale(0, "");
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int** meza = new int* [3];
for (int i = 0; i < 3; ++i)
meza[i] = new int[3];
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
meza[i][j] = 0;
prog(meza);
cout << "\n\nEnd of program, xx: " << endl;
return 0;
}
g
и gg
- это не копии массива, а копии указателя. Выделяйте память под новые массивы и копируйте с помощью memcpy
#include <iostream>
#include <Windows.h>
using std::cout;
using std::cin;
using std::endl;
void prog(int** a) {
int** g = new int* [3];
for (int i = 0; i < 3; ++i)
g[i] = new int[3];
int** gg = new int* [3];
for (int i = 0; i < 3; ++i)
gg[i] = new int[3];
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
g[i][j] = a[i][j];
}
}
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
gg[i][j] = a[i][j];
}
}
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
cout << a[i][j] << " ";
}
cout << endl;
}
g[1][1] = 1;
cout << endl;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
cout << g[i][j] << " ";
}
cout << endl;
}
cout << endl;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
cout << gg[i][j] << " ";
}
cout << endl;
}
cout << endl;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
cout << a[i][j] << " ";
}
cout << endl;
}
}
int main() {
setlocale(0, "");
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int** meza = new int* [3];
for (int i = 0; i < 3; ++i)
meza[i] = new int[3];
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
meza[i][j] = 0;
prog(meza);
cout << "\n\nEnd of program, xx: " << endl;
return 0;
}