Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 0.29 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. When and why to use malloc
  2. #include <stdio.h>
  3.  
  4. int main(int argc, const char *argv[]) {
  5.  
  6. typedef struct {
  7.  char *name;
  8.  char *sex;
  9.  int age;
  10. }student;
  11.  
  12.  
  13. //Now I can do two things
  14. student p;
  15.  
  16. //or
  17. student *p = (student *)malloc(sizeof(student));
  18.  
  19. return 0
  20. }
  21.        
  22. int *p = malloc(sizeof(int)*10);