Last active
October 16, 2015 16:02
-
-
Save tsvx/fe73efb92c770fc64e78 to your computer and use it in GitHub Desktop.
C: Trying integers sizeof and implicit type conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
typedef unsigned short ushort; | |
int main() | |
{ | |
printf("sizeof(sizeof)=%ld\n", sizeof(sizeof(ushort))); // 8 | |
printf("ushort=%ld\n", sizeof(ushort)); // 2 | |
printf("int = %ld\n", sizeof(int)); // 4 | |
ushort a=1, b=3; | |
int d = a-b; | |
printf("ushort 1 - 3 = %d\n", d); // -2 | |
d = b-a; | |
printf("ushort 3 - 1 = %d\n", d); // 2 | |
printf("sizeof(ushort 1 - 3) = %ld\n", sizeof(a-b)); // 4 | |
printf("sizeof(ushort 1 & 3) = %ld\n", sizeof(a&b)); // 4 | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment