42Seoul/CPP Module 01

ex02

재윤 2023. 12. 1. 13:26
반응형
  • 여기서 중요한 것은 포인터와 레퍼런스의 차이를 아는 것

개념을 좀 더 알고 싶으면 나의 글 카테코리에 C++의 레퍼런스에 대한 개념을 보고 오자

#include <iostream>

int	main(void)
{
	std::string str = "HI THIS IS BRAIN";
	std::string *stringPTR = &str;
	std::string &stringREF = str;

	std::cout << "Print Memory address" << std::endl;
	std::cout << "str address : " << &str << std::endl;
	std::cout << "stringPRT address : " << &stringPTR << std::endl;
	std::cout << "stringREF address : " << &stringREF << std::endl;

	std::cout << std::endl;
	std::cout << "Print string" << std::endl;
	std::cout << "str value       : " << str << std::endl;
	std::cout << "stringPRT value : " << *stringPTR << std::endl;
	std::cout << "stringREF value : " << stringREF << std::endl; 
}

 

[C++] 포인터와 레퍼런스(참조)의 차이를 이해해보자

 

[C++] 포인터와 레퍼런스(참조)의 차이를 이해해보자

C++에는 포인터(Pointer)와 레퍼런스(Reference)라는 개념이 있다. 포인터는 C 에도 있었던 개념이며 레퍼런스는 C++ 에서 등장한 개념이다. 언뜻 보면 용도가 비슷한데 정확히 어떤 차이점이 있는지,

woo-dev.tistory.com

 

반응형

'42Seoul > CPP Module 01' 카테고리의 다른 글

ex05(함수 포인터 배열)  (0) 2023.12.02
ex04  (0) 2023.12.01
ex03  (0) 2023.12.01
ex01(객체 포인터 배열 할당)  (0) 2023.12.01
ex00  (0) 2023.12.01