๐Ÿ˜Ž ๊ณต๋ถ€ํ•˜๋Š” ์ง•์ง•์•ŒํŒŒ์นด๋Š” ์ฒ˜์Œ์ด์ง€?

[Embedded ์œ„ํ•œ ํ•œ๋ฐœ์ง ๋‘๋ฐœ์ง๐Ÿพ] ์ž…์ถœ๋ ฅ ์ŠคํŠธ๋ฆผ cin, cout & ํ•จ์ˆ˜ ์‚ฌ์šฉํ•ด๋ณด๊ธฐ & ์ง€์—ญ ๋ณ€์ˆ˜ ๋ณธ๋ฌธ

๐Ÿ‘ฉ‍๐Ÿ’ป IoT (Embedded)/C++

[Embedded ์œ„ํ•œ ํ•œ๋ฐœ์ง ๋‘๋ฐœ์ง๐Ÿพ] ์ž…์ถœ๋ ฅ ์ŠคํŠธ๋ฆผ cin, cout & ํ•จ์ˆ˜ ์‚ฌ์šฉํ•ด๋ณด๊ธฐ & ์ง€์—ญ ๋ณ€์ˆ˜

์ง•์ง•์•ŒํŒŒ์นด 2023. 6. 24. 00:40
728x90
๋ฐ˜์‘ํ˜•

<๋ณธ ๋ธ”๋กœ๊ทธ๋Š” ๋”ฐ๋ฐฐ์”จ ๋‹˜์˜ ์œ ํŠœ๋ธŒ๋ฅผ ์ฐธ๊ณ ํ•ด์„œ ๊ณต๋ถ€ํ•˜๋ฉฐ ์ž‘์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค :-)>

=> [๋”ฐ๋ฐฐ์”จ++] ๋”ฐ๋ผํ•˜๋ฉฐ ๋ฐฐ์šฐ๋Š” C++ | ๋ชจ๋˜ c++, c++ ๊ฐ•์˜, c++ ๊ฐ•์ขŒ, c++ ์–ธ์–ด, ๊ธฐ์ดˆ & c++ ํ”„๋กœ๊ทธ๋ž˜๋ฐ, ์ฝ”๋”ฉ

 

๐Ÿซง ์ž…์ถœ๋ ฅ ์ŠคํŠธ๋ฆผ๊ณผ์˜ ์ฒซ ๋งŒ๋‚จ cin, cout

#include <iostream>		// cout, cin, endl
#include <cstdio>		// printf

int main() {
	using namespace std;
	// ์ž…๋ ฅ
	int x;
	cin >> x;

	// ์ถœ๋ ฅ
	cout << "I love C++" << endl;
	cout << "I am" << x << "years old!" << endl;

	return 0;
}

 

๐Ÿซง ํ•จ์ˆ˜์™€์˜ ์ฒซ ๋งŒ๋‚จ

#include <iostream>

using namespace std;

int addTwoNumbers(int a, int b) {
	int sum = a + b;
	return sum;
}

int multiplyTwoNumbers(int a, int b) {
	int sum = a * b;
	return sum;
}

void printHelloWorld() {
	cout << "Hello World" << endl;
}

int main() {
	cout << addTwoNumbers(3, 4) << endl;
	cout << multiplyTwoNumbers(2, 5) << endl;
	printHelloWorld();
	return 0;
}

 

๐Ÿซง ์ง€์—ญ ๋ณ€์ˆ˜ 1

#include <iostream>

using namespace std;

int main() {
	int x = 0;
	cout << x << " " << &x << endl;

	{
		// ์ง€์—ญ ๋ณ€์ˆ˜ : ์˜์—ญ ๋ฒ—์–ด๋‚˜๋ฉด ์‚ฌ์šฉ X
		// ์ฐจ์ง€ํ•˜๊ณ  ์žˆ๋˜ ๋ฉ”๋ชจ๋ฆฌ๋Š” ์Šคํƒ ๋ฉ”๋ชจ๋ฆฌ๋กœ ๋ฐ˜๋‚ฉ
		// x == 0; ์ด๋ฉด ๊ฐ’ ๊ฐ™๊ฒŒ ๋‚˜์˜ด!!
		int x = 0;
		cout << x << " " << &x << endl; 
		// x์˜ ์ฃผ์†Œ๊ฐ’์ด ๋‹ค๋ฆ„!!
	}
}

 

๐Ÿซง ์ง€์—ญ ๋ณ€์ˆ˜ 2

#include <iostream>

using namespace std;

void doSomething(int x) {
	x = 123;
	cout << x << endl;		// #2
}

int main() {
	int x = 0;

	cout << x << endl;		// #1
	doSomething(x);
	cout << x << endl;		// #3

	return 0;
}

// ๋‚˜์˜ ์˜ˆ์ƒ ๊ฐ’
// 0
// 123
// 0

728x90
๋ฐ˜์‘ํ˜•
Comments