sizeof() confusion

Paul John Falstad pfalstad at stroke.Princeton.EDU
Fri Nov 9 13:09:19 AEST 1990


In article <2665 at cirrusl.UUCP> dhesi%cirrusl at oliveb.ATC.olivetti.com (Rahul Dhesi) writes:
>        char c;
>        c = 'c';     /* char variable holds char value */
>        printf("sizeof c       = %d\n", sizeof c);
>        printf("sizeof 'c'     = %d\n", sizeof 'c');
>        printf("sizeof (char)  = %d\n", sizeof (char));

It prints:

sizeof c = 1
sizeof 'c' = 4
sizeof (char) = 1

Which is no real surprise if you know that 'c' is not a char.
Character literals are really ints.

--
Paul Falstad, pfalstad at phoenix.princeton.edu PLink:HYPNOS GEnie:P.FALSTAD
"Your attention, please.  Would anyone who knows where the white courtesy
phone is located please pick up the white courtesy phone."



More information about the Comp.lang.c mailing list