Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

행복한 개구리

C++ Tutorial - References / Create References 본문

C++/공부내용

C++ Tutorial - References / Create References

HappyFrog 2022. 6. 23. 15:51


 

 

 

참조 생성하기

참조 변수는 기존 변수에 대한 "참조"이며  연산자와 함께 생성됩니다.

 

#include <iostream>

using namespace std;

int main() {
	string food = "Pizza";
	string& meal = food;
}

 

이제 우리는 변수 이름  food  또는  food  변수에 참조하는 참조 이름  meal  둘 다 사용할 수 있습니다:

 

 

예시

#include <iostream>

using namespace std;

int main() {
	string food = "Pizza";
	string& meal = food;

	cout << food << "\n";
	cout << meal;
}