← 설명 글로 돌아가기

값 전달과 참조 전달 예제

각 파일은 독립적으로 실행할 수 있습니다. 아래 명령은 이 저장소의 루트에서 실행합니다.

값 전달

by_value.cc

clang++ -std=c++17 examples/reference/by_value.cc -o /tmp/blog_by_value
/tmp/blog_by_value

예상 출력:

inside: 20
outside: 10

참조 전달

by_reference.cc

clang++ -std=c++17 examples/reference/by_reference.cc -o /tmp/blog_by_reference
/tmp/blog_by_reference

예상 출력:

inside: 20
outside: 20

const 참조 전달

by_const_reference.cc

clang++ -std=c++17 examples/reference/by_const_reference.cc -o /tmp/blog_by_const_reference
/tmp/blog_by_const_reference

예상 출력:

inside: 10
outside: 10

설명 글로 돌아가기