- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
#include<stdio.h>
#include<conio.h>
#define SQUARE(x) (x*x)
void main()
{
clrscr();
int i=3,j,k;
j=SQUARE(i++);
k=SQUARE(++i);
printf("\n%d\n%d\n%d",j,k,i);
getch();
}
答案令人困惑:9 49 7我在想 j=3*4=12, k=6*7=42 , i=7发生了什么事?我错过了什么吗?(x*x)=((x)*(x)) 同样在这里。没关系。
最佳答案
两行:
#define SQUARE(x) (x*x)
j=SQUARE(i++);
翻译成:
j = (i++ * i++);
这是未定义的行为。如果没有中间序列点(并且 *
不是序列点),您不得修改变量两次。
你最好使用类似的东西:
inline int SQUARE (int x) { return x * x; }
可能发生的情况是增量在乘法完成之前或之后一起发生,有效地给你:
i = 3; // i = 3
j = i * i; i++; i++; // j = 9, i = 5
++i; ++i; k = i * i; // i = 7, k = 49
但请记住,这就是这种情况下发生的情况。实现可以自由地以其他方式进行,因为您违反了规则。事实上,如果需要,它可以格式化您的硬盘。这就是未定义行为的本质,定义为(我的斜体):
behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which this International Standard imposes no requirements.
NOTE Possible undefined behavior ranges from ignoring the situation completely with unpredictable results, to behaving during translation or program execution in a documented manner characteristic of the environment (with or without the issuance of a diagnostic message), to terminating a translation or execution (with the issuance of a diagnostic message).
关于C程序:output seems confusing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5181416/
我在这方面需要澄清。我觉得Static library和Dynamic Library这两个术语不正确。 lib1.o + lib2.o + lib3.o->“LinkerOutputFile”(可执
我想为多类多标签分类建立一个混淆矩阵,然后计算精度、召回率和 F1。 一个想法是从训练和测试集中的所有组合中构建它,例如 A1 A2A3 A1A3 A1 x x x A
我希望这是一个非常简单的问题,在 Android 中什么相当于在 PHP 中执行此操作: PHP: 函数 BlahBlah ($first_var,$second_var,$optional_var_
我正在努力理解递归,我想我已经明白了......我正在尝试构建一个搜索函数(如 std::string.find()),用于在给定字符串中搜索另一个字符串例如: Given (big) string:
我有一个列表,其中包含有关用户网络浏览器的信息。该列表由 PHP 通过用户需求调查生成。输出如下所示:(示例): Mozilla/4.0(兼容;MSIE 8.0;Windows NT 6.1;Trid
这是我在这里的第一个问题,所以如果我违反了任何规则,或者没有使用正确的格式,请原谅我 我正在用 java swing 创建一个简单的表单,它由 1 个 JLabel、1 个 JTextField 和
使用分段包创建分段线性回归我在尝试设置自己的断点时看到错误;似乎只有当我尝试设置两个以上时。 (编辑)这是我正在使用的代码: # data bullard <- structure(list(Rt =
据我了解,调用 NSLog(@"Local Time Zone %@",[[NSTimeZone localTimeZone] name]); 为您提供设备的本地时区。它给我的是“US/Central
假设我有一个名为 Navbar 的模板,它包含在 Main 和 About 页面中。在 Navbar 模板中,我有一个搜索栏组件,我只想在 Main 模板上显示它。我定义了一个辅助函数,如下所示: T
我正在 Java 中进行分配,我应该使用我在我的项目中导入的 enumeration 类型 MONTH项目。我的老师写道:“有一个特殊的函数可以将数字转换为月份:月.月(8)”。 我已经写了Month
有同学问我,既然操作系统是扩展机或者虚拟机,那么编译器在生成C程序的汇编代码时是否需要知道寄存器的数量,或者处理器的指令的数量。 我花了一段时间在互联网上搜索,这就是我的想法...... 它不需要知道
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 5 年前。 Improve this ques
我正在尝试理解 initstate 和 initstate_r 的联机帮助页。这两个函数都在初始化随机生成器。如果您有多个线程,则不应使用 initstate,但对于这种情况,您应该使用 initst
据说: When it would yield a class method object, it is transformed into a bound user-defined method ob
我正在学习 JS 函数式编程,并使用 Ramda 进行。 我正在尝试创建一个接受参数并返回列表的函数。这是代码: const list = R.unapply(R.identity); list(1,
我试图在按下“提交”按钮后显示用于“页面加载”的相同加载器。 在页面的最顶部我有: (“gabbia”只是一个容器,而“load_screen”和“loader”是用 css 格式化以获得一个漂亮的
#include #include #define SQUARE(x) (x*x) void main() { clrscr(); int i=3,j,k; j=
#include using namespace std; int myFunc (unsigned short int x ); int main () { unsigned short
在 http://hollywoodnose.com我根据每个页面有多少图片有条件广告。因此,如果有一张图片,我将使用 468 x 60。如果有 4 张图片,我将在第二张图片之后显示 180 x 15
我有一个在数据库上执行全文搜索的搜索查询。 $sql = "SELECT * FROM `tbl_auction_listing` AS `al` JOIN `tbl_user` AS `u` ON
我是一名优秀的程序员,十分优秀!