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

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(다른 사용자 한 명의 중간 판 2개는 보이지 않습니다)
6번째 줄: 6번째 줄:
==문법==
==문법==
{{소스헤더|헤더}}
{{소스헤더|헤더}}
<source lang='C'>
<syntaxhighlight lang='C'>
#include <string.h>
#include <string.h>
</source>
</syntaxhighlight>


{{소스헤더|정의}}
{{소스헤더|정의}}
<source lang='C'>
<syntaxhighlight lang='C'>
void *memcpy(void *dest, const void *src, size_t n);
void *memcpy(void *dest, const void *src, size_t n);
</source>
</syntaxhighlight>


==예시==
==예시==
* int형의 배열 src배열을 dst배열로 복사
* int형의 배열 src배열을 dst배열로 복사
<source lang='C'>
<syntaxhighlight lang='C' run>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
23번째 줄: 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>


==같이 보기==
==같이 보기==
51번째 줄: 43번째 줄:


[[분류: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 }}