Type of character constant

后端 未结 3 680
悲哀的现实
悲哀的现实 2020-12-11 20:45

I am studying physics and in the lecture notes of our programming course it is written that a character constant, in C has type char, where by character con

3条回答
  •  情书的邮戳
    2020-12-11 21:11

    You may find this code elucidating:

    #include 
    int main() {
        printf("size of char is %ld\n", sizeof(char));
        printf("size of const char is %ld\n", sizeof(const char));
        printf("size of int is %ld\n", sizeof(int));
        printf("size of 'x' is %ld\n", sizeof('x'));
    }
    

    Please compile on your system. On my system (OS X, compiling with either gcc -m32 or gcc -m64), the output is:

    size of char is 1
    size of const char is 1
    size of int is 4
    size of 'x' is 4
    

    I hope this helps.

提交回复
热议问题