Skip to content

Instantly share code, notes, and snippets.

@kasramp

kasramp/test.cpp Secret

Created August 1, 2020 23:29
Show Gist options
  • Save kasramp/cf17cbf49687da1dc2e0c97f5402d20e to your computer and use it in GitHub Desktop.
Save kasramp/cf17cbf49687da1dc2e0c97f5402d20e to your computer and use it in GitHub Desktop.
int main(int argc, char *argv[]) {
int x[3] = {1, 2, 3};
int *p;
p=x;
cout << *p; //prints x[0];
cout << ++*p; //prints x[1];
cout << p[1]; //prints x[1];
cout << *x; //prints x[0];
cout << ++*x; //prints x[1];
cout << *++x; //Compile error;
cout << *x++; //Compile error;
p = &x; //Compile error;
p = &x[0]; //p points to first element of x;
cout << *p; //prints x[0];
cout << ++*p; //prints x[1];
cout << p[1]; //prints x[1];
cout << *++p; //prints x[1];
cout << *(++p); //prints x[1];
cout << *(p++); //prints x[0];
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment