I am quite confused by the following code:
#include <stdio.h>
#include <stdint.h>
int main(int argc, char ** argv)
{
uint16_t a = 413;
uint16_t b = 64948;
fprintf(stdout, "%u
", (a - b));
fprintf(stdout, "%u
", ((uint16_t) (a - b)));
return 0;
}
That returns:
$ gcc -Wall test.c -o test
$ ./test
4294902761
1001
$
It seems that expression (a - b) has type uint32_t.
I don't uderstand why since both operators are uint16_t.
Can anyone explain this to me?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…