Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct {
- char name[10];
- } Person;
- int main() {
- // initialize to empty
- Person* p = NULL;
- // check if empty do memory allocated
- if (!p) {
- p = (Person*) malloc(sizeof(Person));
- }
- // set the name
- strcpy(p->name, "yarco"); // the meaning is the same as `p->name = "yarco"`
- printf("I'm %s\n", p->name);
- // free memery
- free(p);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement