malloc free 001 002 003 004 005 006





![/*019*/ printf("₩n"); /*020*/ /*021*/ int. Pointer = (int*)malloc(sizeof(int[5])); /*022*/ int. Pointer[0] = 11; /*023*/ /*019*/ printf("₩n"); /*020*/ /*021*/ int. Pointer = (int*)malloc(sizeof(int[5])); /*022*/ int. Pointer[0] = 11; /*023*/](https://slidetodoc.com/presentation_image_h2/a616e56b8697132d7c0127c09fbaa0ec/image-6.jpg)


![/*021*/ int. Pointer = (int*)malloc(sizeof(int[5])); int. Pointer (004814 a 0) (004814 a 4) (004814 /*021*/ int. Pointer = (int*)malloc(sizeof(int[5])); int. Pointer (004814 a 0) (004814 a 4) (004814](https://slidetodoc.com/presentation_image_h2/a616e56b8697132d7c0127c09fbaa0ec/image-9.jpg)
![[결과] SQ Lab. 10 [결과] SQ Lab. 10](https://slidetodoc.com/presentation_image_h2/a616e56b8697132d7c0127c09fbaa0ec/image-10.jpg)


![/*019*/ printf("₩n"); /*020*/ /*021*/ int. Pointer = (int*)calloc(5, sizeof(int)); /*022*/ int. Pointer[0] = 11; /*019*/ printf("₩n"); /*020*/ /*021*/ int. Pointer = (int*)calloc(5, sizeof(int)); /*022*/ int. Pointer[0] = 11;](https://slidetodoc.com/presentation_image_h2/a616e56b8697132d7c0127c09fbaa0ec/image-13.jpg)



![[결과] SQ Lab. 17 [결과] SQ Lab. 17](https://slidetodoc.com/presentation_image_h2/a616e56b8697132d7c0127c09fbaa0ec/image-17.jpg)
- Slides: 17





(예) malloc()와 free() /*001*/ /*002*/ /*003*/ /*004*/ /*005*/ /*006*/ /*007*/ /*008*/ /*009*/ /*010*/ /*011*/ /*012*/ /*013*/ /*014*/ /*015*/ /*016*/ /*017*/ /*018*/ SQ Lab. /* malloc. Nfree 01(vs 2010) : dynamic allocation and retrocession */ #include "stdio. h" #include "malloc. h" /* #include "stdlib. h" */ void main() { int *int. Pointer; int. Pointer = (int*)malloc(4); *int. Pointer = 1; printf("₩n int. Pointer(%08 x)=>%i", int. Pointer, *int. Pointer); free(int. Pointer); int. Pointer = (int*)malloc(sizeof(int)); *int. Pointer = 3; printf("₩n₩n int. Pointer(%08 x)=>%i", int. Pointer, *int. Pointer); free(int. Pointer); 5
![019 printfn 020 021 int Pointer intmallocsizeofint5 022 int Pointer0 11 023 /*019*/ printf("₩n"); /*020*/ /*021*/ int. Pointer = (int*)malloc(sizeof(int[5])); /*022*/ int. Pointer[0] = 11; /*023*/](https://slidetodoc.com/presentation_image_h2/a616e56b8697132d7c0127c09fbaa0ec/image-6.jpg)
/*019*/ printf("₩n"); /*020*/ /*021*/ int. Pointer = (int*)malloc(sizeof(int[5])); /*022*/ int. Pointer[0] = 11; /*023*/ int. Pointer[1] = 33; /*024*/ int. Pointer[2] = 55; /*025*/ int. Pointer[3] = 77; /*026*/ int. Pointer[4] = 99; /*027*/ /*028*/ int *i; /*029*/ for(i=int. Pointer; i<int. Pointer+5; i++) /*030*/ printf("₩n i(%08 x)=>%i", i, *i); /*031*/ /*032*/ printf("₩n₩n₩n Type any character : "); /*033*/ getchar(); /*034*/ } SQ Lab. 6

/*004*/ #include "malloc. h" malloc() 함수를 정의한 "malloc. h"를 포함시킨다. /*008*/ int *int. Pointer; int. Pointer /*009*/ int. Pointer = (int*)malloc(4); int. Pointer (004814 a 0) /*010*/ *int. Pointer = 1; int. Pointer (004814 a 0) /*012*/ (004814 a 0) 1 free(int. Pointer); int. Pointer SQ Lab. 7

/*014*/ int. Pointer = (int*)malloc(sizeof(int)); int. Pointer (004814 a 0) /*015*/ *int. Pointer = 3; int. Pointer (004814 a 0) /*017*/ (004814 a 0) 3 free(int. Pointer); int. Pointer SQ Lab. 8
![021 int Pointer intmallocsizeofint5 int Pointer 004814 a 0 004814 a 4 004814 /*021*/ int. Pointer = (int*)malloc(sizeof(int[5])); int. Pointer (004814 a 0) (004814 a 4) (004814](https://slidetodoc.com/presentation_image_h2/a616e56b8697132d7c0127c09fbaa0ec/image-9.jpg)
/*021*/ int. Pointer = (int*)malloc(sizeof(int[5])); int. Pointer (004814 a 0) (004814 a 4) (004814 a 8) (004814 ac) (004814 b 0) [0] [1] [2] [3] [4] (004814 a 0) /*022*/ /*023*/ /*024*/ /*025*/ /*026*/ int. Pointer[0] int. Pointer[1] int. Pointer[2] int. Pointer[3] int. Pointer[4] int. Pointer (004814 a 0) = = = 11; 33; 55; 77; 99; (004814 a 0) (004814 a 4) ((004814 a 8) (004814 ac) (004814 b 0) 11 33 55 77 99 [0] [1] [2] [3] [4] /*028*/ int *i; /*029*/ /*030*/ for(i=int. Pointer; i<int. Pointer+5; i++) printf("₩n i(%08 x)=>%i", i, *i); int. Pointer의 각 원소 값을 화면에 나타낸다. SQ Lab. 9
![결과 SQ Lab 10 [결과] SQ Lab. 10](https://slidetodoc.com/presentation_image_h2/a616e56b8697132d7c0127c09fbaa0ec/image-10.jpg)
[결과] SQ Lab. 10


(예) calloc() /*001*/ /*002*/ /*003*/ /*004*/ /*005*/ /*006*/ /*007*/ /*008*/ /*009*/ /*010*/ /*011*/ /*012*/ /*013*/ /*014*/ /*015*/ /*016*/ /*017*/ /*018*/ SQ Lab. /* calloc 01 c. Ncpp : dynamic allocation and retrocession */ #include "stdio. h" #include "malloc. h" /* #include "stdlib. h" */ void main() { int *int. Pointer; int. Pointer = (int*)calloc(1, 4); *int. Pointer = 1; printf("₩n int. Pointer(%08 x)=>%i", int. Pointer, *int. Pointer); free(int. Pointer); int. Pointer = (int*)calloc(1, sizeof(int)); *int. Pointer = 3; printf("₩n₩n int. Pointer(%08 x)=>%i", int. Pointer, *int. Pointer); free(int. Pointer); 12
![019 printfn 020 021 int Pointer intcalloc5 sizeofint 022 int Pointer0 11 /*019*/ printf("₩n"); /*020*/ /*021*/ int. Pointer = (int*)calloc(5, sizeof(int)); /*022*/ int. Pointer[0] = 11;](https://slidetodoc.com/presentation_image_h2/a616e56b8697132d7c0127c09fbaa0ec/image-13.jpg)
/*019*/ printf("₩n"); /*020*/ /*021*/ int. Pointer = (int*)calloc(5, sizeof(int)); /*022*/ int. Pointer[0] = 11; /*023*/ int. Pointer[1] = 33; /*024*/ int. Pointer[2] = 55; /*025*/ int. Pointer[3] = 77; /*026*/ int. Pointer[4] = 99; /*027*/ /*028*/ int *i; /*029*/ for(i=int. Pointer; i<int. Pointer+5; i++) /*030*/ printf("₩n i(%08 x)=>%i", i, *i); /*031*/ /*032*/ printf("₩n₩n₩n Type any character : "); /*033*/ getchar(); /*034*/ } SQ Lab. 13

/*004*/ #include "malloc. h" malloc() 함수를 정의한 "malloc. h"를 포함시킨다. /*008*/ int *int. Pointer; int. Pointer /*009*/ int. Pointer = (int*)calloc(1, 4); int. Pointer (004814 a 0) /*010*/ *int. Pointer = 1; int. Pointer (004814 a 0) /*012*/ (004814 a 0) 1 free(int. Pointer); int. Pointer SQ Lab. 14

/*014*/ int. Pointer = (int*)calloc(1, sizeof(int)); int. Pointer (004814 a 0) /*015*/ *int. Pointer = 3; int. Pointer (004814 a 0) /*017*/ (004814 a 0) 3 free(int. Pointer); int. Pointer SQ Lab. 15

/*021*/ int. Pointer = (int*)calloc(5, sizeof(int)); int. Pointer (004814 a 0) (004814 a 4) (004814 a 8) (004814 ac) (004814 b 0) [0] [1] [2] [3] [4] (004814 a 0) /*022*/ /*023*/ /*024*/ /*025*/ /*026*/ int. Pointer[0] int. Pointer[1] int. Pointer[2] int. Pointer[3] int. Pointer[4] int. Pointer (004814 a 0) = = = 11; 33; 55; 77; 99; (004814 a 0) (004814 a 4) ((004814 a 8) (004814 ac) (004814 b 0) 11 33 55 77 99 [0] [1] [2] [3] [4] /*028*/ int *i; /*029*/ /*030*/ for(i=int. Pointer; i<int. Pointer+5; i++) printf("₩n i(%08 x)=>%i", i, *i); int. Pointer의 각 원소 값을 화면에 나타낸다. SQ Lab. 16
![결과 SQ Lab 17 [결과] SQ Lab. 17](https://slidetodoc.com/presentation_image_h2/a616e56b8697132d7c0127c09fbaa0ec/image-17.jpg)
[결과] SQ Lab. 17