添加两个数字,而无需使用+和 - 运营商运营商、两个、数字

2023-09-11 23:09:23 作者:致命一刀

假设你有两个数字,这两个符号整数,你要总结他们,但不能用你的语言的常规+和 - 运营商。你会怎么做呢?

Suppose you have two numbers, both signed integers, and you want to sum them but can't use your language's conventional + and - operators. How would you do that?

根据 http://www.ocf.berkeley.edu/~ WWU /谜语/ cs.shtml

推荐答案

不是我的,但可爱的

int a = 42;
int b = 17;
char *ptr = (char*)a;
int result = (int)&ptr[b];