23.2 불 자료형 크기 알아보기

이번에는 int 자료형과 bool 자료형의 크기를 알아보겠습니다.

boolean_sizeof.c

#include <stdio.h>
#include <stdbool.h>    // bool, true, false가 정의된 헤더 파일
 
int main()
{
    printf("int의 크기: %d\n", sizeof(int));      // int의 크기: 4: int의 크기는 4바이트
    printf("bool의 크기: %d\n", sizeof(bool));    // bool의 크기: 1: bool의 크기는 1바이트
 
    return 0;
}

실행 결과

int의 크기: 4
bool의 크기: 1

sizeof 연산자로 intbool 자료형의 크기를 구했습니다. 출력 결과에 따르면 int의 크기는 4바이트, bool의 크기는 1바이트입니다. 지금까지 int로 참, 거짓을 표현했는데 intbool은 크기가 다르다는 점을 기억하세요.