gpt4 book ai didi

C编程: A Modern Approach - chapter 10 project 6 - confused

转载 作者:行者123 更新时间:2023-11-30 20:09:45 26 4
gpt4 key购买 nike

有很多人在 github 上发布了本书问题的答案,我看过其中的一些人,它们看起来都非常相似。无论如何,这是其中之一的链接。问题在评论中,答案在下面。

https://github.com/auwsmit/cpama2/blob/master/Ch10/ProgrammingProjects/p6.c

因此,假设我输入的表达式是 75+=

我不明白为什么以下几行有效。

else if (input == '+')
push(operandA + operandB);

从我的理解来看,操作数A = '7' = ascii 55 & 操作数B = '5' = ascii 53。

所以不会 operandA + operandB = ascii 108 = 'l'

从这里我的理解是,这个字符被分配给内容[0],这意味着 main 最终应该打印出 108 作为答案,但事实并非如此。它打印出正确答案 12。

我哪里出错了?

最佳答案

您在给定的代码中看到这一行了吗:

if (input >= '0' && input <= '9')
push(input - '0');

当输入 7 和 5 而不是 55 和 53 时,将存储 (55-48=7) 和 (53-48=5)。

关于C编程: A Modern Approach - chapter 10 project 6 - confused,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49809532/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com