Created
September 3, 2014 03:23
-
-
Save elliottwilliams/22b3a58e4cb80ae7fafd to your computer and use it in GitHub Desktop.
C overflow demonstration
This file contains 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
λ ~/Desktop/ ./overflow | |
Before any reassignment: | |
i = 512 = 0x200 | |
c = 127 = 0x7f | |
When i = c, then c = i: | |
i = 127 = 0x7f | |
c = 127 = 0x7f | |
When c = i, then i = c: | |
i = 0 = 0x0 | |
c = 0 = 0x0 |
This file contains 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> | |
int main() { | |
int i = 512; | |
char c = 127; | |
printf("Before any reassignment: \n"); | |
printf("i = %d \t= 0x%x\n", i, i); | |
printf("c = %d \t= 0x%x\n", c, c); | |
i = c; | |
c = i; | |
printf("When i = c, then c = i:\n"); | |
printf("i = %d \t= 0x%x\n", i, i); | |
printf("c = %d \t= 0x%x\n", c, c); | |
i = 512; | |
c = 127; | |
c = i; | |
i = c; | |
printf("When c = i, then i = c:\n"); | |
printf("i = %d \t= 0x%x\n", i, i); | |
printf("c = %d \t= 0x%x\n", c, c); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment