It won't hurt to try

[C++/윈도우프로그래밍응용]3. 변수, 자료형, 연산자 본문

C++/윈도우프로그래밍응용

[C++/윈도우프로그래밍응용]3. 변수, 자료형, 연산자

yongki.doki 2021. 9. 12. 14:24

Variable

dataType

byte
정수형 short 2
int, long 4
long long 8
문자형 char 1
부울형 bool 1
부동소수점형 float 4
(long) double 8

Variable initialization

초기화 방식

C++11이전의 초기화 방식

int i = 100;

C++11 초기화 방식

int i { 100 };

선언방법

자주 사용하는 자료형의 선언방법

int i = 100;
char ch = 'a';
string str = "hello";
bool isValid = true;

const

// const
const double PI = 3.14;

Operator

산술연산자

float x = 2;
float y = 5;
float sum = x + y; // 7
float sub = x - y; // -3
float mul = x * y; // 10
float div = x / y; // 0.4
cout.precision(3); // 소수점 2자리까지
cout << fixed; 소수점 자릿수 고정

비교연산자

// ==
string s1 = "Good";
string s2 = "good";
bool b = (s1 == s2); // false

// >=
// <=

 

300x250
300x250
Comments