Skip to content

Instantly share code, notes, and snippets.

@tsvx
Last active October 16, 2015 16:02
Show Gist options
  • Save tsvx/fe73efb92c770fc64e78 to your computer and use it in GitHub Desktop.
Save tsvx/fe73efb92c770fc64e78 to your computer and use it in GitHub Desktop.
C: Trying integers sizeof and implicit type conversion
#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