Correct format specifier for return value of sizeof() in C

前端 未结 3 1466
青春惊慌失措
青春惊慌失措 2020-11-30 10:53

I have the following code:

#include

int main()
{
    printf(\"The \'int\' datatype is \\t\\t %lu bytes\\n\", sizeof(int));
    printf(\"The \         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 11:11

    In C the type of a sizeof expression is size_t.

    The printf specifier to use is %zu. Example:

    printf("The 'int' datatype is \t\t %zu bytes\n", sizeof(int));
    

    It has been possible to use this since the 1999 version of the C standard.

提交回复
热议问题