Skip to content

Instantly share code, notes, and snippets.

@shadowmint
Created March 14, 2016 02:45
Show Gist options
  • Save shadowmint/034da48deedeca17b197 to your computer and use it in GitHub Desktop.
Save shadowmint/034da48deedeca17b197 to your computer and use it in GitHub Desktop.
#include <iostream>
int foo[10][10];
void init() {
for (auto i = 0; i < 10; ++i) {
for (auto j = 0; j < 10; ++j) {
foo[i][j] = i + j;
}
}
}
int** caller() {
int** x = new int *;
for (auto i = 0; i < 10; ++i) {
x[i] = &foo[i][0];
}
return x;
}
int main(int argc, char *argv[]) {
init();
auto x = caller();
for (auto i = 0; i < 10; ++i) {
for (auto j = 0; j < 10; ++j) {
std::cout << foo[i][j] << " vs " << x[i][j] << std::endl;
}
}
delete x;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment