两数相加,而无需使用运营商 [英] Adding two numbers without using operators
问题描述
我发现这下code的另外两个数字而无需使用 +
运营商。
code以添加3和4:
的printf(%D的printf(%* C%* C,3',4''));
现在的printf()
返回结果的字符数
和%* C
忽略下一个字符,它遇到。但尽管如此,我不能够理解这code。任何帮助将是AP preciated。
的printf(%* C,N,C)
打印字符 C
, N
倍。所以code打印后跟4个空格3位,和 printf的
返回打印的字符的数目,这显然是3 + 4,在完成的问题。对>
I found this following code for addition of two numbers without using the +
operator.
code to add 3 and 4:
printf("%d",printf("%*c%*c",3,' ',4,' '));
Now printf()
returns the number of characters in the result
and %*c
ignores the next character that it encounters. But still, I am not able to understand this code. Any help would be appreciated.
printf("%*c", n, c)
prints the character c
, n
times. So the code prints 3 spaces followed by 4 spaces, and printf
returns the number of characters printed, which is obviously 3 + 4, completing the problem.
这篇关于两数相加,而无需使用运营商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!