본문 바로가기
C++/뇌를 자극하는 C++

[C++] 챕터 4 - 변수 : 정보를 담는 방법

by Minkyu Lee 2023. 4. 20.

// 예제 4-1 : 변수의 정의와 사용

# include <iostream>
using namespace std;

int main()
{
	// 변수 정의
	int a;
	int b;
	int c;

	// 각 변수에 값 넣기
	a = 100;
	b = 200;
	c = 300;
	
	// 화면에 출력
	cout << a << "," << b << "," << c << "\n";

	return 0;
}

/*
정의가 선행되어야한다.
위에서부터 아래로 순차적으로 코드가 읽힌다.
*/

 

// 예제 4-6 : 변수간의 대입

#include <iostream>
using namespace std;

int main()
{
	// 정의 및 초기화
	int d = 1000, e = 2000;
	cout << "d = " << d << ", e = " << e << "\n";

	// 값 복사
	d = e;
	cout << "d = " << d << ", e = " << e << "\n";

	return 0;
}

댓글