728x90
반응형
더보기
# include <stdio.h>
void my_func(int n);
int main(){
my_func(1);
return 0;
}
void my_func(int n)
{
printf("Level %d, address of variable n = %p\n",n,&n); // 주소 달라짐
my_func(n+1);
// 무한 호출시에는 재귀 호출을 사용하지 않는다. 스택에 부하가 가기 때문.
// 스택이 다 차면 강제적으로 종료
// 재귀 호출 시에는 조건문 사용.
// if(n < ?) my_func(n+1);
}
더보기
# include <stdio.h>
void my_func(int n);
int main(){
my_func(1);
return 0;
}
void my_func(int n)
{
printf("Level %d, address of variable n = %p\n",n,&n); // 주소 달라짐
if(n < 5)
my_func(n+1);
// 무한 호출시에는 재귀 호출을 사용하지 않는다. 스택에 부하가 가기 때문.
// 스택이 다 차면 강제적으로 종료
// 재귀 호출 시에는 조건문 사용.
// if(n < ?) my_func(n+1);
printf("Level %d, address of variable n = %p\n",n,&n); // 스택에 쌓이고 나서 빠지는 상황
}
스택에 쌓는 과정에서의 메모리주소와 쌓이고 나서 빠지는 상황에서의 메모리 주소는 동일하다.
728x90
반응형
최근댓글