Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-std=c99 -Wall -Wextra -Wpedantic -Wshadow
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- char *ptr = NULL;
- printf("(1) %p\n", (void*) ptr);
- ptr = malloc(10);
- if (!ptr)
- {
- printf("error: cannot allocate memory.\n");
- return 1;
- }
- printf("(2) %p\n", (void*) ptr);
- free(ptr);
- printf("(3) %p\n", (void*) ptr);
- ptr = NULL;
- printf("(4) %p\n", (void*) ptr);
- return 0;
- }
- /*
- output:
- (1) (nil)
- (2) 0x557cbfb32670
- (3) 0x557cbfb32670
- (4) (nil)
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement