Skip to content

Instantly share code, notes, and snippets.

@LizardLeliel
Last active August 29, 2015 14:08
Show Gist options
  • Save LizardLeliel/81836fb9c3b9696e0785 to your computer and use it in GitHub Desktop.
Save LizardLeliel/81836fb9c3b9696e0785 to your computer and use it in GitHub Desktop.
Using p[-1], and getting defined behaviour
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int *p = (int*)malloc(sizeof(int)*2);
*p = 4;
++p;
*p = 2;
printf("%d", p[-1]); /* Prints 4 */
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment