"C언어 memcpy()"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(사용자 2명의 중간 판 6개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개념==
==개념==
;C언어 memcpy()
;C언어 memcpy()
*지정한 크기 만큼의 메모리 영역 복사
* "memory copy"
* 지정한 크기 만큼의 메모리 영역 복사


==문법==
==문법==
<source lang='C'>
{{소스헤더|헤더}}
<syntaxhighlight lang='C'>
#include <string.h>
</syntaxhighlight>
 
{{소스헤더|정의}}
<syntaxhighlight lang='C'>
void *memcpy(void *dest, const void *src, size_t n);
</syntaxhighlight>
 
==예시==
* int형의 배열 src배열을 dst배열로 복사
<syntaxhighlight lang='C' run>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
10번째 줄: 23번째 줄:
#define ARR_SIZE 6
#define ARR_SIZE 6


void printArray(int *arr, int n)
void printArray(int *arr, int n) {
{
     int i;
     int i;
 
     for (i = 0; i < n; i++) printf("%d ", arr[i]);
     for (i = 0; i < n; i++) {
        printf("%d ", arr[i]);
    }
     printf("\n");
     printf("\n");
}
}


int main()
int main() {
{
     const int src[ARR_SIZE] = {0, 1, 2, 3, 4, 5};
     const int src[ARR_SIZE] = {0, 1, 2, 3, 4, 5};
     int dst[ARR_SIZE];
     int dst[ARR_SIZE];
     memcpy(dst, src, sizeof(src));
     memcpy(dst, src, sizeof(src));
     printArray(dst, ARR_SIZE);
     printArray(dst, ARR_SIZE);
     return 0;
     return 0;
}
}
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==
* [[C언어 배열 복사]]
* [[C언어 강좌]]
* [[C언어 강좌]]


[[분류:C]]
[[분류:C]]
[[분류: string.h]]

2020년 11월 2일 (월) 02:40 기준 최신판

1 개념[ | ]

C언어 memcpy()
  • "memory copy"
  • 지정한 크기 만큼의 메모리 영역 복사

2 문법[ | ]

헤더
#include <string.h>
정의
void *memcpy(void *dest, const void *src, size_t n);

3 예시[ | ]

  • int형의 배열 src배열을 dst배열로 복사
#include <stdio.h>
#include <string.h>

#define ARR_SIZE 6

void printArray(int *arr, int n) {
    int i;
    for (i = 0; i < n; i++) printf("%d ", arr[i]);
    printf("\n");
}

int main() {
    const int src[ARR_SIZE] = {0, 1, 2, 3, 4, 5};
    int dst[ARR_SIZE];
    memcpy(dst, src, sizeof(src));
    printArray(dst, ARR_SIZE);
    return 0;
}

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}