동적할당으로 메모리 공간을 할당 받고, 그 공간의 주소를 포인터로 받는다.
이때 이용된 포인터 변수의 값은 free() 함수를 이용하기 전까지 바뀌어서는 안된다.
memcpy와 같은 함수를 이용해 할당받은 주소공간을 이용할 수 있다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
#include<stdio.h>
#include<tchar.h>
#include<stdlib.h>
#include<string.h>
int main(void) {
char szBuffer[12] = { "HelloWorld" };
char* pszData = malloc(sizeof(szBuffer));
memcpy(pszData, szBuffer, sizeof(szBuffer));
puts(pszData);
free(pszData);
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5; text-decoration:none">Colored by Color Scripter
|
'Programing > 명강의 C' 카테고리의 다른 글
포인터 배열 (0) | 2019.05.12 |
---|---|
C 포인터 이해하기 (0) | 2019.05.10 |