Created
January 8, 2021 21:31
-
-
Save gvnwltrs/b1fd84eea4c4595ef6bfc81dc1db5db8 to your computer and use it in GitHub Desktop.
Pointers and Arrays #C
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
### array that uses malloc | |
``` | |
#include <stdio.h> | |
int main() | |
{ | |
char* word = (char *)malloc(10); // creates a contiguous block of 10 chars on the heap | |
// another way: | |
// char* word = malloc(10 * sizeof(char* ); | |
//bonus: change the size of the array | |
word = (char *)realloc(5); | |
free(word); // now has to be freed since it is now on the heap | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment