Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct {
  6. char name[10];
  7. } Person;
  8.  
  9. int main() {
  10. // initialize to empty
  11. Person* p = NULL;
  12.  
  13. // check if empty do memory allocated
  14. if (!p) {
  15. p = (Person*) malloc(sizeof(Person));
  16. }
  17.  
  18. // set the name
  19. strcpy(p->name, "yarco"); // the meaning is the same as `p->name = "yarco"`
  20.  
  21. printf("I'm %s\n", p->name);
  22.  
  23. // free memery
  24. free(p);
  25. return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement