Skip to content

Instantly share code, notes, and snippets.

@gvnwltrs
Created January 8, 2021 21:31
Show Gist options
  • Save gvnwltrs/b1fd84eea4c4595ef6bfc81dc1db5db8 to your computer and use it in GitHub Desktop.
Save gvnwltrs/b1fd84eea4c4595ef6bfc81dc1db5db8 to your computer and use it in GitHub Desktop.
Pointers and Arrays #C
### 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