분류 전체보기140 문제 03-1 [구조체 내에 함수정의하기] #define _CRT_SECURE_NO_WARNINGS#include using namespace std;struct Point{ int xpos; int ypos; void MovePos(int x, int y) { xpos += x; ypos += y; } void ShowPosition() { cout 2024. 8. 2. 문제 02-4 [C++의 표준함수 호출] #define _CRT_SECURE_NO_WARNINGS#include #include using namespace std;int main(){ char str1[] = "ABC 123"; char str2[] = "ABd 123"; char str3[50]; cout char str1[] = "ABC 123";char *str1="ABC 123";배열의 크기를 할당하는것에 있어 차이가 있다. 포인터를 사용하면 문자열이 저장된 데이터 세그먼트 영역의 주소를 가리키는 포인터를 나타내는것이다. 따라서 아래는 읽기 전용이고 위에는 수정할 수 있다. 2024. 8. 1. 문제 02-3 [구조체에 대한 new & delete 연산] #include using namespace std;typedef struct __point{ int xpos; int ypos;}Point;Point& PntAdder(const Point& p1, const Point& p2);Point& PntAdder(const Point& p1, const Point& p2){ Point* tp = new Point; tp->xpos = p1.xpos + p2.xpos; tp->ypos = p1.ypos + p2.ypos; return *tp;}int main(){ Point p1 = { 1,2 }; Point p2 = { 2,3 }; Point &np=PntAdder(p1,p2); cout함수 내에 선언된 변수를 참조형으로 반환하려면 해당 변수는 어떻게 선.. 2024. 8. 1. 문제 02-2 [const 포인터와 const 참조자] #include using namespace std;int main(){ const int num = 12; const int* p = # const int &ref = *p; cout 2024. 8. 1. 문제 02-1 [참조자 기반의 Call-by-reference 구현] 문제 1#include using namespace std;int plusfunc(int &num1){ num1++; return num1;}int changefunc(int &num2){ num2 = (-1) * num2; return num2;}int main(){ int val1 = 10; int val2 = 20; plusfunc(val1); changefunc(val2); cout 문제 2참조자는 상수를 참조 못한다.문제 3#include using namespace std;void SwapPointer(int *(&pref1), int* (&pref2)){ int *ptr=pref1; pref1 = pref2; pref2 = ptr;}int main(){ int num1 = 5; int* pt.. 2024. 8. 1. 문제 01-2 [함수 오버로딩] #include using namespace std;void swap(int *num1, int *num2){ int temp; temp = *num1; *num1 = *num2; *num2 = temp;}void swap(char *ch1, char* ch2){ char temp; temp = *ch1; *ch1 = *ch2; *ch2 = temp;}void swap(double* dbl1, double* dbl2){ double temp; temp = *dbl1; *dbl1 = *dbl2; *dbl2 = temp;}int main(){ int num1 = 20, num2 = 30; swap(&num1, &num2); cout 2024. 7. 31. 이전 1 ··· 5 6 7 8 9 10 11 ··· 24 다음