나는 youtube에서 운동을했는데 그가 가지고있는 것과 같은 해결책으로 끝났지 만 그의 코드는 포인터가 가리키고있는 주소를 얻을 수 있었지만 광산을 컴파일하고 실행할 때 오류 세그먼테이션 오류 (코어 덤프), 나는 어떻게해서든지 내가 접근해야하는 것이 아닌 메모리에 접근하고 있는가? 그의 코드는 어떻게 실행되었지만 내 코드는 실행되지 않았는가? printf ("num의 주소는 % d \ n", * ptr)에 문제가 있다는 것을 알고 있습니다. 하지만 YouTube에서 라인 작업을했지만 내 컴파일러에서 않습니다.분할 (코어 덤프)이 왜 발생합니까?
#include <stdio.h>
int print_int_ptr();
int main(){
int num;
num = 10;
print_int_ptr(num);
return(0);
}
/* dont forget that in between the assignment of ptr = &num */
/* Take the address of an integer as a parameter, and print out both the
* address and the integer itself
*/
void print_int_ptr(int *ptr){
printf("The address of num is %d\n", *ptr);
printf("The value of num is %d\n", ptr);
}
이 문제를 확인하기 위해 경고가 켜진 상태로 프로그램을 컴파일하십시오. –