Size of character ('a') in C/C++

前端 未结 4 1246
天命终不由人
天命终不由人 2020-11-22 03:08

What is the size of character in C and C++ ? As far as I know the size of char is 1 byte in both C and C++.

In C:

#include 

        
4条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 03:23

    In C the type of character literals are int and char in C++. This is in C++ required to support function overloading. See this example:

    void foo(char c)
    {
        puts("char");
    }
    void foo(int i)
    {
        puts("int");
    }
    int main()
    {
        foo('i');
        return 0;
    }
    

    Output:

    char
    

提交回复
热议问题