728x90
값에 의한 호출
-
Java - Call by Value & Call By ReferenceLanguage/Java 2022. 2. 21. 13:23
Call by Value & Call by Reference Call by Value(값에 의한 호출) void function(int number) { number = 20; } void main() { int number = 10; function(number); printf("%d", number); // 출력되는 값은 10 } - 함수가 호출될 때, 메모리 공간 안에서는 함수를 위한 별도의 임시공간이 생성되고, 종료 시 해당 공간이 사라진다. - 해당 호출 방식은 함수 호출 시 전달되는 변수 값을 복사해서 함수 인자로 전달한다. 이때, 복사된 인자는 함수 안에서 지역적으로 사용되기 때문에 local value의 속성을 가진다. - 따라서, 함수 안에서 인자 값이 변경되더라도, 외부 변수 값은 변경..