공부/C++ (10) 썸네일형 리스트형 C++_Reference 참조자 #include void Swap(int& a, int& b) { int temp = a; a = b; b = temp; } int main(void) { int n = 1; int& ref = n; int a = 1, b = 2; std::cout C++_Const 키워드 #include int main(void) { const int num1 = 1; int num2 = 2; const int* ptr1 = &num2; int* const ptr2 = &num2; const int* const ptr3 = &num2; const int& ref = 3; return 0; } Const 키워드는 상수화를 시켜주는 키워드이다. const int num1 = 1; 위의 코드의 경우에는 num1이 1의 값으로 상수화 된 것이다. 때문에 num1=2; 처럼 num1의 값을 변경시키는 코드는 에러를 일으킨다. num1의 값의 수정을 막기 위해서 사용한다. const int* ptr1 = &num2; 포인터의 경우이다. 위의 코드의 경우에는 const가 자료형 왼편에 나왔다. *pt.. C++_Using 키워드 #include namespace Uhon { using namespace std; void Toy() { cout C++_Name Space(이름 공간) #include namespace programming { void Uhon() { std::cout C++_Inline 함수 #include inline int sum(int a, int b, int c) { return a + b + c; } int main(void) { std::cout C++_함수의 Default Value #include int sum(int a = 1, int b = 2, int c = 3); int main(void) { std::cout C++_함수 오버로딩(Function Overloading) 함수의 오버 로딩이란 동일한 이름의 함수를 여러 개 정의하여 사용할 수 있는 것이다. 하지만 함수의 오버 로딩의 조건이 있는데 조건으로는 이름은 같지만 Parameter의 형태나 개수가 달라야 한다. 반환형이 다른 것은 오버 로딩 조건에 해당하지 않는다. #include int sum(int a, int b) { std::cout C++_지역변수 선언 C++은 지역 변수 선언 위치에 대해서 제한을 두지 않는다. #include int main(void) { int a = 0; std::cout 이전 1 2 다음