Skip to content

Instantly share code, notes, and snippets.

@mejariamol
Created December 25, 2018 10:18
Show Gist options
  • Save mejariamol/9c9d87ca5497073b1dba07d6b5e01727 to your computer and use it in GitHub Desktop.
Save mejariamol/9c9d87ca5497073b1dba07d6b5e01727 to your computer and use it in GitHub Desktop.
code 2 | C++ code to illustrate behind the scene
#include <iostream>
using namespace std;
// This method is used to get
// pretty addresses.
int addr(void * p) {
return (long)p%1000;
};
int main() {
int zeroArr[2];
int i;
for (i=0; i<2; i++) {
zeroArr[i] = 0;
}
int oneArr[2];
for (i=0; i<=2; i++) {
oneArr[i] = 1;
}
cout << "zeroArr[1] " << addr(zeroArr+1) << endl;
cout << "zeroArr[0] " << addr(zeroArr) << endl;
cout << "oneArr[1] " << addr(oneArr+1) << endl;
cout << "oneArr[0] " << addr(oneArr) << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment