1 개념[ | ]
- 배열 복사
2 memcpy() 함수 이용[ | ]
C
CPU
0.1s
MEM
18M
0.1s
Copy
#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;
}
0 1 2 3 4 5
3 자작 함수 사용[ | ]
C
Copy
#include <stdio.h>
#include <string.h>
#define ARR_SIZE 6
void arrayCopy(int *dst, const int *src, int n) {
int i;
for (i = 0; i < n; i++) {
dst[i] = src[i];
}
}
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];
arrayCopy(dst, src, ARR_SIZE);
printArray(dst, ARR_SIZE);
return 0;
}
Loading
4 같이 보기[ | ]
편집자 John Jeong Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.
- 분류 댓글:
- C 배열 (1)
C언어 array max() 구현 ― John Jeong