添加两个数字,而无需使用+和 - 运营商 [英] Add two numbers without using + and - operators

查看:112
本文介绍了添加两个数字,而无需使用+和 - 运营商的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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];

这篇关于添加两个数字,而无需使用+和 - 运营商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆