'A' Byte Count Question

Asked 2 years ago, Updated 2 years ago, 71 views

#define _CRT_SECURE_NO_WARNINGS  
#include <stdio.h>


int main()
{
    int size;


    int num1 = 10;
    double num2 = 0X18;
    long double num3 = 17.1e-3;
    double num4 = 3.14;
    char num5 = 'A';
    double num6 = 3.14F;



    printf("Literal's storage size\n(1)10: %dByte \n(2) 0X18: %dByte \n(3) 17.1e-3: %dByte \n(4) 3.14: %dByte \n(5) 'A': %dByte \n(6) 3.14F: %dByte \n", soof(104), size(0X18), soof(104), soof(104), sof)




    return 0;
}

In visual c++, the results of sizeof(char) and sizeof('A') are different, so shouldn't the character constant 'A' be an int type, so the size should be output as 4 bytes? If you print out the code according to the visual studio 2019 above, 'A' is printed as 1 byte, so what's the problem?

sizeof c

2022-09-20 17:40

1 Answers

C and c++ are different languages. It's one of the differences between the two languages.

In c++, 'A' is char, unlike 'c'.


2022-09-20 17:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.