- When and why to use malloc
- #include <stdio.h>
- int main(int argc, const char *argv[]) {
- typedef struct {
- char *name;
- char *sex;
- int age;
- }student;
- //Now I can do two things
- student p;
- //or
- student *p = (student *)malloc(sizeof(student));
- return 0
- }
- int *p = malloc(sizeof(int)*10);