C++

[C/C++ 강좌] 73강. 9부 종합문제 1 (동적 할당과 객체 복사)

코다람쥐 2022. 1. 18. 17:51

https://www.youtube.com/watch?v=htpHACPnwx8&list=PLlJhQXcLQBJqywc5dweQ75GBRubzPxhAk&index=78

 

1. 다음 프로그램의 실행 결과는?

#include <iostream>
using namespace std;

int main() {
	char str[] = "Hello, World!";

	cout << str << endl;
	cout << *str << endl;
}

 

 

 

 

 

 

 

 

 

 

 

정답.

 

 

 

 

 

1. □ 부분에 알맞은 기호를 넣고, 출력 결과를 예측해보세요.

#include <iostream>
using namespace std;

int main() {
	int a = 10, b = 20, c = 30;
	int* p = □a;
	int& r = □b;
	int** pp = □p;
	int* (&rp) = □p;

	r = c / □p;
	rp = □c;
	□pp = 40;
	□p = 50;
	*pp = □a;
	□rp = 60;

	cout << a << endl;
	cout << b << endl;
	cout << c << endl;
	cout << *p << endl;
	cout << r << endl;
	cout << **pp << endl;
	cout << *rp << endl;
}

 

 

 

 

 

 

 

 

 

 

정답.

#include <iostream>
using namespace std;

int main() {
	int a = 10, b = 20, c = 30;
	int* p = &a;
	int& r = b;
	int** pp = &p;
	int* (&rp) = p;

	r = c / *p;
	rp = &c;
	**pp = 40;
	*p = 50;
	*pp = &a;
	*rp = 60;

	cout << a << endl;
	cout << b << endl;
	cout << c << endl;
	cout << *p << endl;
	cout << r << endl;
	cout << **pp << endl;
	cout << *rp << endl;
}