Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment 19: Improve memory allocation #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Assignment-19/assignment19.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ int main (void)

//ptr is now the memory address of the beginning of this 10 char element array.
//we used the sizeof() function to make sure that the size of memory allocated is 10 units on any host
ptr = malloc(10 * sizeof(char));
ptr = calloc(10, sizeof(*ptr));

//if malloc fails, our ptr pointer will be pointing towards a NULL value, this checks for that
if (ptr == NULL)
{
printf("Memory could not be allocated.");
return 1;
}
else
else
{
printf("Memory was successfully allocated.");
//this makes sure we don't keep memory allocated that we're not using.
Expand Down