--- layout: post author: Pascal Cuoq date: 2012-01-20 12:06 +0200 categories: conversions-and-promotions facetious-colleagues format: xhtml title: "Constants quiz" summary: --- {% raw %}
What does the following program print?
long long l; #include <stdio.h> int main() { l = -0x80000000; printf(\%lld" l); } $ gcc t.c && ./a.out
And this one? (beware trick question)
long long l; #include <stdio.h> int main() { l = -2147483648; printf("%lld" l); } $ gcc t.c && ./a.out
What "it's too difficult!"? Okay here is a hint in the form of a third question:
long long l; #include <stdio.h> int main() { l = -2147483648; printf("%lld" l); } $ gcc -std=c99 t.c && ./a.out
You are probably reading this on a computer on which the answers are "2147483648" "2147483648" and "-2147483648".
{% endraw %}