본문 바로가기

Programming/C언어

[C언어] 컴파일러별로 지원하는 자료형의 크기 체크하기

컴파일러별로 지원하는 자료형의 크기 체크하기



 프로그램을 만들기 전에 쓰고 있는 컴파일러가 지원하는 자료형의 크기를 체크하면 도움이 되지 않을까 생각합니다. C언어로 작성되어있지만 쓰고 있는 프로그래밍 언어로 바꿔서 자료형의 크기를 체크하실 수 있습니다.


----------------------------------------------------------------------------------------------------------------------------------


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* 컴파일러별로 지원하는 자료형의 크기 체크 */
#include <stdio.h>
//#include <stdlib.h>  //system()함수 선언, Dev-C++일 경우 주석 제거
#include <limits.h> //정수형
#include <float.h>  //double, float형
 
int main(void)
{  
    printf("char 크기 : %dbytes\n",sizeof(char));
    printf("int 크기 : %dbytes\n",sizeof(int));
    printf("int max : %d, int min : %d\n",INT_MAX,INT_MIN );
    printf("unsigned int max : %u\n",UINT_MAX);
 
    printf("short 크기 : %dbytes\n",sizeof(short));
    printf("short max : %d, short min : %d\n",SHRT_MAX,SHRT_MIN );
    printf("unsigned short max : %u\n",USHRT_MAX);
    
    printf("long  크기 : %dbytes\n",sizeof(long));
    printf("long long 크기 : %ldbytes\n",sizeof(long long));
 
    printf("float 크기 : %dbytes\n",sizeof(float)); 
 
    printf("double 크기 : %dbytes\n",sizeof(double)); 
    printf("double max : %g, double min : %g\n",DBL_MAX,DBL_MIN );  
    printf("long double 크기 : %dbytes\n",sizeof(long double)); 
 
    // system("PAUSE");   //Dev-C++일 경우 주석 제거
    
    return 0;  
}
cs


---------------------------------------------------------------------------------------------------------------------------------


Mac 환경


---------------------------------------------------------------------------------------------------------------------------------


Windows 10 (64bit) / Microsoft Visual Studio 2015



---------------------------------------------------------------------------------------------------------------------------------


Windows 10 (64bit) / Dev-C++