์ƒˆ์†Œ์‹

๐Ÿ‘ฉ‍๐Ÿ’ป C

C์–ธ์–ด - ์ •์ˆ˜ ์ž๋ฃŒํ˜• | ์ตœ๋Œ“๊ฐ’ ์ตœ์†Ÿ๊ฐ’ , sizeof ์—ฐ์‚ฐ์ž ( <limits.h> <stdint.h> )

  • -

* sizeof ์—ฐ์‚ฐ์ž

sizeof์—ฐ์‚ฐ์ž๋Š” ์ž๋ฃŒํ˜•์˜ ํฌ๊ธฐ๋ฅผ byte๋‹จ์œ„๋กœ ๋ฆฌํ„ดํ•œ๋‹ค. (unsighned๊ฐ€ ๋ถ™์–ด๋„ ํฌ๊ธฐ๋Š” ๊ฐ™๋‹ค.)

#include <stdio.h>

int main()
{
    printf("char: %d, short: %d, int: %d\n",sizeof(char), sizeof(short),  sizeof(int));
    return 0;
}

์ถœ๋ ฅ >>>>> char: 1, short: 2, int: 4

 

 

 

* <limits.h>

limits ํ—ค๋”ํŒŒ์ผ์—๋Š” ์ž๋ฃŒํ˜•์˜ ์ตœ๋Œ“๊ฐ’ , ์ตœ์†Ÿ๊ฐ’์ด ์ •์˜๋˜์–ด์žˆ๋‹ค. 

char์˜ ์ž๋ฃŒํ˜•์€ -128 ~ 127์ด๋‹ค.  limits๋ฅผ ์ด์šฉํ•˜์—ฌ ์ถœ๋ ฅํ•ด๋ณด๋ฉด

#include <stdio.h>
#include <limits.h>

int main()
{
    char char_min = CHAR_MIN;
    char char_max = CHAR_MAX;

    printf("char range : %d ~ %d", char_min, char_max);
    return 0;
}


์ถœ๋ ฅ >>>>> char range : -128 ~ 127

 

limits.h์˜ ํ‚ค์›Œ๋“œ

 

 

*<stdint.h>

์ •์ˆ˜ ์ž๋ฃŒํ˜•์˜ ํฌ๊ธฐ๋ฅผ ์ •ํ• ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค€๋‹ค. 

#include <stdio.h>
#include <stdint.h>

int main()
{
    int8_t num1 = 123;
    int num2 = 123;
    printf("num1's size : %d, num2's size : %d", sizeof(num1), sizeof(num2));
    return 0;
}

//์ถœ๋ ฅ >>>>> num1's size : 1, num2's size : 4

num1 ๊ณผ num2๋Š” ๋ชจ๋‘ 123์ด์ง€๋งŒ, ํฌ๊ธฐ๊ฐ€ ๋‹ค๋ฅด๊ฒŒ ๋‚˜์˜ค๋Š”๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.