sizeof() confusion

D'Arcy J.M. Cain darcy at druid.uucp
Sat Nov 10 23:32:04 AEST 1990


In article <2665 at cirrusl.UUCP> Rahul Dhesi writes:
> [...]
>     main() {
>        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));
>     }
>
>Non-C wizards should try to guess what the program will print before
>they run the program.

OK, I'll byte.  What's the suprise?  I get 1, 4 and 1 on my 386 system
which is exactly what I expected.  Were you suprised that "'c'" was 4?
You shouldn't be.  That expression evaluates to an int, not a char.

-- 
D'Arcy J.M. Cain (darcy at druid)     |
D'Arcy Cain Consulting             |   I support gun control.
West Hill, Ontario, Canada         |   Let's start with the government!
+ 416 281 6094                     |



More information about the Comp.lang.c mailing list