동적할당

BugDict/C

[C언어]"Error in `./a.out': malloc(): memory corruption (fast): 0x0000000001a1d030"해결

문제상황: C 언어로 개발하던 중 동적할당을 활용한 코드에서 에러가 발생했습니다. 에러가 발생한 코드: #include #include typedef struct { int id; char name[20]; } Employee; int main() { Employee* empList; int empCount = 5; empList = (Employee*)malloc(empCount * sizeof(Employee)); for (int i = 0; i

BugDict/C

[C언어] "Segmentation fault (core dumped)" 해결

문제상황: 다음 코드는 배열을 동적으로 할당한 후, 포인터를 사용하여 배열에 접근하려고 합니다. 하지만 실행시 "segmentation fault" 에러가 발생하며 프로그램이 종료됩니다. #include #include int main() { int *arr; int size; printf("Enter the size of the array: "); scanf("%d", &size); arr = (int *) malloc(size * sizeof(int)); for (int i = 0; i

Bug Detector
'동적할당' 태그의 글 목록