Desc :

char 문자형

int 정수형

double , float 실수형

bool 논리형 - true, false 둘 중 하나의 값

string 문자열 --> 문자형 자료형 string 사용하기 위한 해더 파일 <string>

 


Source Code :

#include <iostream>
#include <string>

using namespace std;

int main()
{
	char ch = 'C';
	int integer = 100;
	double pi = 3.141592;
	bool is_true = true;
	string word = "Hello string";

	cout << "char: " << ch << endl;
	cout << "int: " << integer << endl;
	cout << "double: " << pi << endl;
	cout << "bool: " << is_true << endl;
	cout << "string: " << word << endl;

	return 0;
}

 


Result :

'C++' 카테고리의 다른 글

[C++] 009 순환문  (0) 2021.01.22
[C++] 008 조건문  (0) 2021.01.22
[C++] 006 사칙연산 축약  (0) 2021.01.22
[C++] 005 사칙연산  (0) 2021.01.22
[C++] 004 상수  (0) 2021.01.22

Desc :

x=x+2 ---> x+=2

 


Source Code :

#include <iostream>

using namespace std;

int main()
{
	int two = 2;
	int eight = 8;
	int sum = 0;

	sum += two;
	sum += eight;

	cout << "2 + 8 = " << sum << endl;

	return 0;
}

 


Result :

'C++' 카테고리의 다른 글

[C++] 008 조건문  (0) 2021.01.22
[C++] 007 자료형  (0) 2021.01.22
[C++] 005 사칙연산  (0) 2021.01.22
[C++] 004 상수  (0) 2021.01.22
[C++] 003 변수  (0) 2021.01.22

Desc :

 


Source Code :

#include <iostream>

using namespace std;

int main()
{
	int one = 1;
	int two = 2;
	int three = 3;
	int four = 4;

	cout << "1 + 3 = " << one + three << endl;
	cout << "4 - 2 = " << four - two << endl;
	cout << "2 * 3 = " << two * three << endl;
	cout << "4 / 2 = " << four / two << endl;

	cout << "2 + 3 * 4 = " << two + three * four << endl;
	cout << "1 + 4 / 2 = " << one + four / two << endl;

	return 0;
}

 


Result :

'C++' 카테고리의 다른 글

[C++] 007 자료형  (0) 2021.01.22
[C++] 006 사칙연산 축약  (0) 2021.01.22
[C++] 004 상수  (0) 2021.01.22
[C++] 003 변수  (0) 2021.01.22
[C++] 002 콘솔창 출력  (0) 2021.01.22

Desc :

 

변하지 않고 변하지 않는 값

const로 선언


Source Code :

#include <iostream>

using namespace std;

int main()
{
	const int MY_BIRTH_YEAR = 1998;

	cout << "나의 출생년도 : " << MY_BIRTH_YEAR << "년" << endl;

	return 0;
}

 


Result :

'C++' 카테고리의 다른 글

[C++] 006 사칙연산 축약  (0) 2021.01.22
[C++] 005 사칙연산  (0) 2021.01.22
[C++] 003 변수  (0) 2021.01.22
[C++] 002 콘솔창 출력  (0) 2021.01.22
[C++] 001 C++ 시작  (0) 2021.01.22

Desc :

 

 


Source Code :

#include <iostream>

using namespace std;

int main()
{
	int x = 1;
	int y = 2;
	int sum = x + y;

	cout << "1+2=" << sum << endl;
    
    return 0;
}

 


Result :

'C++' 카테고리의 다른 글

[C++] 006 사칙연산 축약  (0) 2021.01.22
[C++] 005 사칙연산  (0) 2021.01.22
[C++] 004 상수  (0) 2021.01.22
[C++] 002 콘솔창 출력  (0) 2021.01.22
[C++] 001 C++ 시작  (0) 2021.01.22

Desc :

cin >> 변수 : 콘솔창을 통해 입력받아 해당 변수에 할당함

 

cout << : 콘솔창을 통해 출력

 

endl : 콘솔창 커서를 한 줄 밑으로 내린다

 


Source Code :

#include <iostream>

using namespace std;

int main()
{
	int number = 0;

	cin >> number;

	cout << "입력한 숫자는 " << number << " 입니다." << endl;

	return 0;
}

 


Result :

'C++' 카테고리의 다른 글

[C++] 006 사칙연산 축약  (0) 2021.01.22
[C++] 005 사칙연산  (0) 2021.01.22
[C++] 004 상수  (0) 2021.01.22
[C++] 003 변수  (0) 2021.01.22
[C++] 001 C++ 시작  (0) 2021.01.22

Desc :

 iostream - 입출력 사용하기 위한 해더파일

 

using namespace std - std 공간 안에 있는 이름들을 쓰겠다고 미리 약속

 

cout <<  - 명령 프롬프트에 출력하겠다

 

return 0; - c++에선 소스코드 맨 뒤에 적어 퓨터에게 프로그램 종료를 알린다 -> main 함수 int 반환형


Source Code :

#include <iostream>

using namespace std;

int main()
{
	cout << "Hello c++" << endl;

	return 0;
}

 


Result :

'C++' 카테고리의 다른 글

[C++] 006 사칙연산 축약  (0) 2021.01.22
[C++] 005 사칙연산  (0) 2021.01.22
[C++] 004 상수  (0) 2021.01.22
[C++] 003 변수  (0) 2021.01.22
[C++] 002 콘솔창 출력  (0) 2021.01.22

+ Recent posts