프로그래밍 언어/C & C++

[C/C++] 자료형 정리

김꿍디꿍디 2024. 12. 12. 00:15
반응형

정수 자료형의 크기 및 범위

* LLP64/IL32P64, Windows

* ()안에 있는 단어는 생략 가능

이름 크기 최소 범위 최대 범위
char
signed
char
1byte = 8bit -128 127
unsigned char 1byte = 8bit 0 255
short (int) 2byte = 16bit -32,768 32,767
unsigned short (int) 2byte = 16bit 0 65,535
int
signed int
4 byte = 32bit -2,147,483,648 2,147,483,647
unsigned (int) 4 byte = 32bit 0 4,294,967,295
long (int) 
signed long (int)
4 byte = 32bit -2,147,483,648 2,147,483,647
unsigned long (int) 4 byte = 32bit 0 4,294,967,295
long long (int)
signed long long (int)
8 byte = 64bit -9,223,372,036,854,775,808 9,223,372,036,854,775,807
unsigned long long (int) 8 byte = 64bit 0 18,446,744,073,709,551,615

 

long과 int의 차이

  int long
정의 CPU의 레지스터와 동일한 크기의 변수 32bit(4byte)를 저장하는 확장된 크기의 변수
크기 플랫폼에 따라 달라짐 4byte로 고정
16bit OS 2byte = 16bit 4byte = 32bit
32bit OS 4byte = 32bit
4byte = 32bit
64bit OS 8byte = 64bit 4byte = 32bit

* 서로 다른 int의 크기로 문제가 발생하여
정의와 다르게 64bit OS에서는 32bit로 유지시킴

32bit까지는 아키텍쳐에 따라서 크기가 달라지지만, 그 이상은 4byte로 고정
Windows : 4byte = 32bit
Linux, Mac : 8 byte = 64bit

* OS별로 또 달라진다고 함..

참고

https://codingwell.tistory.com/12

 

C/C++ 의 모든 자료형 정리

▼ 정수 자료형의 크기 및 범위(LLP64/IL32P64, Windows) 자료형크기범위비교 char signed char 1바이트, 8비트 -128~127 unsigned char 1바이트, 8비트 0~255 short short int 2바이트, 16비트 -32,768~32,767 int 생략 가능 unsign

codingwell.tistory.com

https://blog.naver.com/passith/70152718749

 

[C/C++] c언어에서의 int, long 차이점

 c언어에서 int와 long은 크기나 부호 여부가 동일하며 따라서 표현할 수 있는 수의 범위도  완...

blog.naver.com

 

https://hackerpark.tistory.com/entry/C%EC%96%B8%EC%96%B4-int-%EC%99%80-long-%EC%9D%80-%EB%AC%B4%EC%97%87%EC%9D%B4-%EB%8B%A4%EB%A5%BC%EA%B9%8C-short-short-int-int-long-int-long-long-long

 

[C언어] int 와 long 은 무엇이 다를까? (short, short int, int, long int, long, long long)

역사 컴퓨터는 지금의 32bit 64bit 가 아닌 8bit 16bit 가 주도했던 시절이 있었다. 당연하겠지만 64bit 가 아니라 32bit 도 처리할 수 없는 컴퓨터가 많았던 시절이었다. 당시에(아직까지도) CPU 시장을 주

hackerpark.tistory.com

https://geuninote.tistory.com/78

 

[C/C++] 자료형 크기 및 범위 정리

자료형의 크기 C언어에서 자료형(data type)의 크기를 파악하는 것은 중요합니다. 우리가 프로그래밍을 할 때 사용하는 변수가 메모리에 어느 정도 공간을 차지하는지 포인터로 접근할 때 어떤 단

geuninote.tistory.com

 

반응형