gpt4 book ai didi

c - 请解释一下输出

转载 作者:行者123 更新时间:2023-11-30 21:49:26 24 4
gpt4 key购买 nike

#include <stdio.h>

int main() {
int a[4] = {1, 2, 3, 4};
int b[4] = {1, 2, 3, 4};
int n = &b[3] - &a[2];
printf("%d\n", n);
}

这道题的输出是-3,谁能解释一下这是怎么来的?

最佳答案

减去“不相关”的指针,即指向不同对象的指针是未定义的。

C11-6.5.6-9

When two pointers are subtracted, both shall point to elements of the same array object, or one past the last element of the array object;

关于c - 请解释一下输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25084258/

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