What happens here? sizeof(short_int_variable + char_variable)

前端 未结 5 1714
鱼传尺愫
鱼传尺愫 2020-12-03 22:03
#include 
 int main()        
{

           short int i = 20;

            char c = 97;

            printf(\"%d, %d, %d\\n\", sizeof(i), sizeof(c), s         


        
5条回答
  •  离开以前
    2020-12-03 22:56

    The data type of a is "short int". -32768 ~ +32767

    The data type of c is "char". 0 ~ 255

    When you add a to c it is not either short int nor char, it becomes int!

    Here is is an example code which help you to get the variable data type:

    #include 
    
    int main()
    {
        short int a = 1;
        char c = 'A';
        std::cout << typeid(a + c).name() << std::endl;
    
        return 1;
    }
    

提交回复
热议问题