Created
June 13, 2018 10:41
-
-
Save jwendell/0e22fb0b18efaf696ba46eca83cc9f0f to your computer and use it in GitHub Desktop.
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(int argc, char const *argv[]) | |
{ | |
if (argc != 2) { | |
fprintf(stderr, "Usage: %s <MEM SIZE>\n", argv[0]); | |
return 1; | |
} | |
printf("Allocating %s bytes of memory...\n", argv[1]); | |
int size = atoi(argv[1]); | |
char *mem = calloc(size, 1); | |
printf("Allocated successfuly %p\n", mem); | |
printf("Using that memory...\n"); | |
for (int i=0; i < size; i++) | |
mem[i] = (i % 254) + 1; | |
printf("Success.\n"); | |
printf("Freeing memory...\n"); | |
free(mem); | |
printf("Success.\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment