Last active
August 29, 2015 14:08
-
-
Save LizardLeliel/81836fb9c3b9696e0785 to your computer and use it in GitHub Desktop.
Using p[-1], and getting defined behaviour
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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