목록Develop/C++ (80)
오븐 노트
CPP_study.cpp #include using namespace std; #include "Test1.h"; int main() { Test_1(); return 0; } test1.cpp #include using namespace std; #include "Test1.h"; #include "Test2.h"; // #pragma once 중복체크 발생 void Test_1() { Test_2(); } void Test_2() { cout
#include #include using namespace std; const int MAX = 100; int board[MAX][MAX] = {}; int N; void PrintBoard() { for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { cout
코딩 테스트 출제 가능성 #include using namespace std; // 문제1) 문자열 길이를 출력하는 함수 int StrLen(const char* str) { // str라는 문자열의 길이를 반환 int count = 0; while (str[count] != '\0') count++; return count; } // 문제2) 문자열 복사 함수 char* StrCpy(char* dest, char* src) { // #1 배열 형식 int count = 0; while (src[count]) { dest[count] = src[count]; count++; } dest[count] = '\0'; return dest; // #2 포인터 형식 //char* ret = dest; //whi..
#include using namespace std; // main // - EnterLobby (PlayerInfo) // -- CreatePlayer // -- EnterGame (MonsterInfo) // --- CreateMonsters // --- EnterBattle enum PlayerType { PT_Knight = 1, PT_Archer = 2, PT_Mage = 3, }; enum MonsterType { MT_Slime = 1, MT_Orc = 2, MT_Skeleton = 3, }; struct StatInfo { int hp = 0; int attack = 0; int defence = 0; }; void EnterLobby(); void PrintMessage(const cha..
포인터나 참조처럼 주소를 다룰때는 그 주소가 정말 끝까지 유효한지 항상 습관처럼 생각하고 있어야하며 어지간해서는 스택에서 스택과 관련된 데이터의 주소를 바깥으로 넘겨주려는 행동은 조심해야함 스택에서만 존재하는 값의 주소를 외부로 가져간다는것 자체가 말이 안되고 절대 하면 안되는 행위 항상 함수와 주소의 생명 주기를 생각하고 있어야함 #include using namespace std; // 포인터나 참조처럼 주소를 다룰때는 그 주소가 정말 끝까지 유효한지 항상 습관처럼 생각하고 있어야하며 // 어지간해서는 스택에서 스택과 관련된 데이터의 주소를 바깥으로 넘겨주려는 행동은 조심해야함 // 스택에서만 존재하는 값의 주소를 외부로 가져간다는것 자체가 말이 안되고 절대 하면 안되는 행위 // 항상 함수와 주소의..
어셈블리 기준 다차원이나 일차원이나 약간의 연산 순서 차이가 있을뿐 성능은 같다. 결국 개발자가 보기 편하게 만들어진게 다차원 배열. #include using namespace std; int main() { int map[5][5] = { { 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1 }, { 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 0 }, { 1, 1, 1, 1, 1 }, }; for (int y = 0; y < 5; y++) { for (int x = 0; x < 5; x++) { int info = map[y][x]; cout
사실상 2차 포인터를 초과하여 들어갈 일은 거의 없다. 있다면 소스가 문제가 있다고 볼 수 있을정도 #include using namespace std; void SetNumber(int* a) { *a = 1; } void SetMessage(const char* a) { // .rdata Bye주소[B][y][e][\0] // [매개변수][RET][지역변수(msg(Hello주소))] [매개변수(a(Hello주소))][RET][지역변수] // [매개변수][RET][지역변수(msg(Hello주소))] [매개변수(a(Bye주소))][RET][지역변수] // [매개변수][RET][지역변수(msg(Hello주소))] a = "Bye"; } void SetMessage(const char** a) { // [매..
#include using namespace std; void Swap(int& a, int& b) { int temp = a; a = b; b = temp; return; } void Sort(int numbers[], int count) { for (int i = 0; i < count; i++) { int best = i; for (int j = i + 1; j < count; j++) { if (numbers[j] < numbers[best]) best = j; } if (i != best) Swap(numbers[i], numbers[best]); } } void ChooseLotto(int numbers[]) { // TODO : 랜덤으로 1~45 사이 숫자 6개 (단, 중복 X) srand(..