값이있는 컬렉션이 있고 컬렉션의 항목 중 하나를 가리키는 포인터를 지정하고 싶습니다. 내가 newInteger의 주소로 그래서 그 changeVar 기능 후, randomPointer 점을 어떻게다른 개체를 가리 키도록 포인터를 변경하는 방법?
void changeVar(int * var) {
int newInteger = 99;
var = &newInteger;
}
int main() {
// create a random pointer and initialize to NULL
int * randomPointer= 0;
// the printf prints out it's address as 0. good.
printf("address: %d \n\r", randomPointer);
// pass the pointer to a function which should change where the pointer points
changeVar(randomPointer);
// the printf below should print the value of the newInteger and randomPointer should point to newInteger value address
printf("value: %d \n\r", *randomPointer);
return 0;
}
을 : 여기
이 작동하지 않습니다 유사한 예이다?추신. randomPointer
예라고 부릅니다. 나는 나쁜 모범을 보였다. 실제의 경우 객체는 정적이다. –