c, cpp

C언어 자료형 종류(C data types)

blackbearwow 2024. 6. 19. 23:25

C언어의 컴파일러마다 자료형의 크기가 다르다. C의 표준을 정하는 ANSI에서 정확한 자료형의 크기를 정하지 않고, 다음과 같은 정도로만 자료형의 크기를 표준화하고있기 때문이다.

"short와 int는 최소 2바이트이되, int는 short와 크기가 같거나 더 커야 한다."

자료형의 크기는 sizeof연산자를 사용하면 알 수 있다.

 

1. 메인 타입 (Main types)

자료형 크기 서식 문자(format specifier) 범위
char 1바이트 %c -128 ~ +127
unsigned char 1바이트 %c 0 ~ +255
short
short int
signed short
signed short int
2바이트 %hi 또는 %hd -32768 ~ +32767
unsigned short
unsigned short int
2바이트 %hu 0 ~ +65535
int
signed
signed int
4바이트 %i 또는 %d -2147483648 ~ +2147483647
unsigned
unsigned int
4바이트 %u 0 ~ +4294967296
long
long int
signed long
signed long int
4바이트 %li 또는 %ld -2147483648 ~ +2147483647
unsigned long
unsigned long int
4바이트 %lu 0 ~ +4294967296
long long
long long int
signed long long
signed long long int
8바이트 %lli 또는 %lld -9223372036854775808 ~ +9223372036854775807
unsigned long long
unsigned long long int
8바이트 %llu 0 ~ +18446744073709551615
float 4바이트 %f %F %g %G %e %E %a %A ±3.4x10^-37 ~ ±3.4x10^+38
double 8바이트 %lf %lF %lg %lG %le %lE %la %lA ±1.7x10^-307 ~ 1.7x10^+308
long double 8바이트 이상 %Lf %LF %Lg %LG %Le %LE %La %LA  double 이상의 표현범위

 

2. 배열 (Arrays)

int cat[10]; // array of 10 elements, each of type int
int a[10][8]; // array of 10 elements, each of type 'array of 8 int elements'

 

3. 포인터 (Pointers)

char *square;
long *circle;
int *oval;
char *pc[10]; // array of 10 elements of 'pointer to char'
char (*pc)[10]; // pointer to a 10-element array of char

 

4. 구조체 (Structures)

struct birthday {
	char name[20];
    int day;
    int month;
    int year;
}
struct birthday John;

 

5. 유니온 (Unions)

union {
	int i;
    float f;
    struct {
    	unsigned int u;
        double d;
    } s;
} u;

 

 

6. 함수 포인터 (Function Pointers)

int (*my_int_f)(int) = &abs;
// the & operator can be omitted, but makes clear that the "address of" abs is used here

 

 

참고: https://en.wikipedia.org/wiki/C_data_types

 

'c, cpp' 카테고리의 다른 글

C++ Standard Template Library(STL)  (0) 2024.07.02
C언어 연산자 우선순위(Operator Precedence in C)  (0) 2024.06.19
C언어의 기본 문법  (0) 2024.06.19
C언어의 이해  (0) 2024.05.27
구조체 비트 필드 (struct bit field)  (0) 2024.03.03