What's the correct way to use printf to print a size_t?

前端 未结 3 1186
礼貌的吻别
礼貌的吻别 2020-11-22 00:18

Size_t is defined as an unsigned integer, but the size of it depends on whether you\'re on a 32 or 64-bit machine. What\'s the correct and portable

3条回答
  •  粉色の甜心
    2020-11-22 01:01

    Try using the %zu format string

    size_t val = get_the_value();
    printf("%zu",val);
    

    The z portion is a length specifier which says the argument will be size_t in length.

    Source - http://en.wikipedia.org/wiki/Printf#printf_format_placeholders

提交回复
热议问题