Skip to content

Instantly share code, notes, and snippets.

@pbrisbin
Created June 7, 2011 21:30
Show Gist options
  • Select an option

  • Save pbrisbin/1013222 to your computer and use it in GitHub Desktop.

Select an option

Save pbrisbin/1013222 to your computer and use it in GitHub Desktop.
malloc?
#include <stdlib.h>
#include <stdio.h>
struct person_t {
char *name;
int age;
};
int main() {
struct person_t *person;
/* this, */
person = malloc(sizeof person);
/* or this? */
person = calloc(1, sizeof *person);
/* and why? */
person->name = "pat";
person->age = 26;
printf("%s is %i years old\n", person->name, person->age);
free(person);
}
@pbrisbin

pbrisbin commented Jun 7, 2011

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment