그래서 포인터를 다시 배우려고 시도했는데 숫자를 입력하면 Visual Studio에서 오류가 발생했습니다. 내가 p_array++;
에 문제가 있음을 알고p_array ++ 다음에 "Project.exe가 중단 점을 트리거했습니다."; in Visual Studio 2015
// Includes
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;
// Variables
int amount;
// Main function
int main()
{
cout << "How many numbers should be in this array: ";
cin >> amount;
int *p_array;
p_array = new int[amount];
for (int i = 0; i < amount; i++)
{
cout << (int)p_array << endl;
p_array++;
}
delete[] p_array;
_getch();
return 0;
}
: 다음은 소스입니다.
또한 Code : Blocks에서이 코드를 컴파일하려고 시도했을 때 완벽하게 작동했습니다 (코드 블록에서 컴파일 할 때 을 으로 변경 함).
P. 나는 ++ C에 새로운 해요 : P
문제는'delete [] p_array;'버그가있는 이유는'p_array'가 더 이상 루프를 통해 증가했기 때문에 new를 사용하여 할당 된 주소를 가리 키지 않기 때문입니다. – drescherjm
@drescherjm 고마워요! 팁을 사용하여 수정했습니다. – fantoro