char * c; c = (char *) a; return &c[b];} 以上在vc中由于类型不匹配,编译不通过,可以使用下面的方法int add(int a,int b){
int AddWithoutArithmetic(int a,int b)
{
if(b==0)
return a;
int sum=a^b; //将各位相加,不考虑进位
int carry=(a&b)<<1; //计算相加时的进位值
return AddWithoutArithmetic(sum,carry);
}
int main()
{
int a=2,b=4;
printf("%d",AddWithoutArithmetic(a,b));
return 0;
}
编译通过。