S_pot

C++_정수형 자료형과 실수형 자료형 본문

C++

C++_정수형 자료형과 실수형 자료형

S_pot 2021. 8. 19. 12:20
#include <iostream>
#include <climits> // 자료형별 최대값을 볼 수 있는 함수가 저장되어 있는 라이브러리

using namespace std;

int main() {
	// 정수형: 소수부가 없는 수
	// 음의 정수, 0, 양의 정수
	// short, int, long, long long
	// 변수의 크기를 잘파악해서 알맞은 자료형을 사용해 메모리를 절약한다.
	// 실수형: 소수부가 있는 수

	float a = 3.14;
	int b = 3.14;

	cout << a << " " << b << endl;

	int n_int = INT_MAX;
	short n_short = SHRT_MAX;
	long n_long = LONG_MAX;
	long long n_llong = LLONG_MAX;

	cout << sizeof n_int << endl;	// sizeof: byte로 표시
	cout <<  n_int << endl;

	cout << sizeof n_short << endl;	
	cout << n_short << endl;

	cout << sizeof n_long << endl;	
	cout << n_long << endl;

	cout << sizeof n_llong << endl;	
	cout << n_llong << endl;

	unsigned int a;	// unsigned: 음의 값을 제외 / 음의 값을 제외한 만큼 양의 값을 지원한다.
	unsigned short a;
	unsigned long a;
	unsigned long long a;

	return 0;
}

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

C++_산술연산자와 auto  (0) 2021.08.19
C++_const 제한자와 데이터형 변환  (0) 2021.08.19
C++_문자형 자료형과 bool형 자료형  (0) 2021.08.19
C++_변수 선언과 규칙  (0) 2021.08.19
C++_Hello, World  (0) 2021.08.19