fork(1) download
  1. #include <cstdio>
  2.  
  3. typedef unsigned char uint8_t;
  4. typedef unsigned int uint32_t;
  5.  
  6. int main() {
  7. uint8_t foo = 5;
  8. uint8_t bar = 250;
  9.  
  10. // Gives value of 11
  11. uint8_t diff8bit = foo - bar;
  12. uint32_t diff1 = static_cast<uint32_t>(diff8bit);
  13.  
  14. // Gives value of 4294967051
  15. uint32_t diff2 = static_cast<uint32_t>(foo) - static_cast<uint32_t>(bar);
  16.  
  17. // Gives value of 4294967051
  18. uint32_t diff3 = static_cast<uint32_t>(foo - bar);
  19.  
  20. printf("diff1 = %u\n", diff1);
  21. printf("diff2 = %u\n", diff2);
  22. printf("diff3 = %u\n", diff3);
  23.  
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
diff1 = 11
diff2 = 4294967051
diff3 = 4294967051