본문 바로가기

전체 글

(241)
허상 포인터(댕글링 포인터) 댕글링 포인터? 해제된 메모리 영역을 가리기는 포인터를 댕글링 포인터라고 한다. int *a = new int(10); int *b = a; cout
L-value, R-value L-value, R-value 는 c++11 이전과 이후로 개념을 다르게 잡는다. c++11 이전에는 연산에서 왼쪽에 존재 할 수 있는 값, 오른쪽에 존재해야하는 값으로 L-value, R-value를 나눌 수 있다. c++11 이후에도 맞는 말이지만 좀 더 추가된 개념이 있다. lvaue 등호의 왼쪽과 오른쪽 전부 존재 가능 식별자를 가지고 있다. 해당 문장을 벗어난 후 사용 가능하다. 주소 연산자로 주소를 구할 수 있다. 참조를 리턴하는 함수. rvalue 등호의 오른쪽에만 존재 가능. 식별자가 없다 해당 문장에서만 사용 주소 연산자로 주소를 구하는게 불가능하다. value 를 리턴하는 함수, 임시객체 등등 int a = 0; int b = 25; // a,b 는 Lvalue로 식별자를 가지는 변수로..
백준 10845 #include #include #include using namespace std; class Queue { private: int* queue; int first = 0, end = 0; int index = 0; int output = 0; public: Queue(int num) { queue = new int[num]; } ~Queue() { delete[] queue; } public: void Push(int num) { queue[index] = num; index++; } int Pop() { if (first == index) { return -1; } else { output = queue[first]; first++; return output; } } int Size() { if (..
백준 4153 #include #include using namespace std; int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); while (1) { int a, b, c; cin >> a >> b >> c; if (a == 0 && b == 0 && c == 0) { break; } else if (sqrt((a * a + b * b)) == sqrt(c * c) || sqrt((a * a + c * c)) == sqrt(b * b) || sqrt((b * b + c * c)) == sqrt(a * a)) { cout
백준 11654 #include using namespace std; int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); char a; cin >> a; int as = (int)a; cout
백준 1157 쉬운 문제라고 생각했는데 생각보다 어려웠다. 문자를 아스키코드를 이용하여 int로 형변환 후 num 의 인덱스로 넣는 것은 쉽게 했다. 그런데 해당 인덱스 값(int)를 다시 아스키코드로 만드는데 시간이 걸렸다. 결국 c 언어 char 의 기본조차 제대로 이해못했었던 것 같다.... char(n) 으로 n 값에 i + 65 로 설정해서 다시 대문자를 넣어주었다. 문제를 너무 어지럽게 푼 것만 같아서 다른 풀이를 더 찾아봐야겠다.. #include #include #include #include using namespace std; int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); string al; cin >> al; vector num(1000..
백준 10950 #include using namespace std; int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); int input = 0; cin >> input; for (int i = 0; i > a >> b; cout
백준 2750 수 정렬하기 1 #include #include #include using namespace std; int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); vector vectors; int input = 0; cin >> input; for (int i = 0; i > num; vectors.push_back(num); } for (int i = 0; i vectors[j]) { int temp = ve..