const 포인터와 const 참조자
자칫 잘 못 생각하면 헷갈릴 수 있음.
#include <iostream> using namespace std; int main(void) { const int num=20; const int* ptr=# const int& ref=*ptr;// int& ref=num;와 같다. const int* (&ref2)=ptr;// ref2는 포인터 변수 ptr의 별명 cout << "num : "<< num << endl; cout << "*ptr : "<< *ptr << endl; cout << "ref : "<< ref << endl; cout << "*ref2 : "<< *ref2 << endl<<endl; cout << "&num : "<< &num << endl; cout << "ptr : "<< ptr << endl; cout << "&ref : "<< &ref << endl; cout << "ref2 : "<< ref2 << endl<<endl; cout << "&ptr : "<< &ptr << endl; cout << "&ref : "<< &ref << endl; cout << "&ref2 : "<< &ref2 << endl; } |
'프로그래밍 > C++' 카테고리의 다른 글
난수 사용하기 (0) | 2013.07.25 |
---|---|
참조자와 함수의 호출관계 (0) | 2013.07.24 |
new & delete 기본 사용법 (0) | 2013.07.23 |
참조자(Reference)를 이용한 Swap() 함수 (0) | 2013.07.23 |
간단한 은행계좌 관리 프로그램 (0) | 2013.07.21 |
범위지정 연산자 (Scope Resolution Operator) (0) | 2013.07.20 |
이름공간(namespace) 기본형 (0) | 2013.07.20 |