parent
e93647efdf
commit
c46ae60780
@ -0,0 +1,32 @@ |
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
|
||||
int main() |
||||
{ |
||||
const int COUNT = 5; |
||||
|
||||
// 동적 메모리 할당, ptr에 동적으로 할당된 메모리의 시작주소 저장
|
||||
int *ptr = (int*)malloc(sizeof(int) * COUNT); |
||||
if (!ptr) |
||||
{ |
||||
printf("Fail to malloc\n"); |
||||
return 1; |
||||
} |
||||
|
||||
for (int i = 0; i < COUNT; i++) |
||||
{ |
||||
ptr[i] = i * 10; // 값 초기화
|
||||
printf("%d ", ptr[i]); // 값 출력
|
||||
} |
||||
printf("\n"); |
||||
|
||||
free(ptr); |
||||
|
||||
printf("\n"); |
||||
for (int i = 0; i < COUNT; i++) |
||||
{ |
||||
printf("%d ", ptr[i]); // 값 출력
|
||||
} |
||||
|
||||
return 0; |
||||
} |
Loading…
Reference in new issue