전체 글 43

Const 정리

Const 란 Constant의 약자로, 변수를 상수화 하고자 할때 사용하는 키워드이다. const 위치에 ('*'의 왼쪽, 오른쪽) 따라서 상수화 대상을 변경할 수 있다. [포인터가 참조하는 값을 상수화] const int* ptr = &value; ptr = &value2; // ok *ptr = 10; // error [포인터 변수를 상수화] int* const ptr = &value; ptr = &value2 // error *ptr = 10; // ok const 객체 객체를 const로 생성하면 const 멤버함수만 호출할 수 있다.(객체 내 데이터를 수정할 수 없기 떄문) class MyClass { public: void AddNum(int num) const; void AddNum2(in..

프로그래밍/C++ 2023.10.08

함수 오버로딩

함수 오버로딩이란 매개변수만 다른 동일한 함수명을 여러개 정의할 수 있는 기능이다. C에서는 복수 함수명을 허용하지 않지만 C++은 함수 오버로딩을 지원한다. 매개변수의 자료형 및 개수가 달라야한다. int Function(int a); int Function(int a, int b); int Function(double a, double b); const 여부로 오버로딩이 가능하다. (단, 매개변수가 포인터 또는 참조형 이어야한다.) void Function(char* a); void Function(const char* a); const 함수는 const 객체에서만 호출할 수 있다. class MyClass { void Function(char* a) { } void Function(char* a) ..

프로그래밍/C++ 2023.10.04

파이썬 문자열

문자열 포매팅 문자열에 값을 삽입하는 방법이다. 크게 세가지로 사용할 수 있다. 포맷코드에 대입 "this is %s" % "apaple" "this is %d %s" % (3, "apaple") format 함수 사용 "this is {} {}".format(3, apple) "this is {0} {1}".format(3, apple) "this is {number} {name}".format(number=3, name=apple) f 문자열 포매팅(파이선 3.6 이상) 문자열 앞에 f 접두어를 붙여서 사용한다. f "this is {number} {name}" f "this is {number} {dict["number"]}" 문자열 관련 함수 함수 기능 예시 비고 count 개수 반환 a.coun..