【问题标题】:Questions regarding default integer value [closed]关于默认整数值的问题 [关闭]
【发布时间】:2018-01-20 09:42:18
【问题描述】:

当我对以下代码进行一些小改动时,我注意到了一些差异:

#include<stdio.h>

 int main()
 {
    int arrow;
    printf("%d\n", arrow);
    int wheel[12]={17, 38, 23, 17, 19, 41, 13, 17, 12, 11, 15, 23};
    int initialValue = wheel[arrow];
    printf("%d\n", initialValue);
    arrow = (arrow + 1) % 12;
    printf("%d\n", arrow);
 }

当我擦除最后两行时,箭头的初始值为 1,它对应于数组中的值“38”。但是,在完整的代码中,箭头的初始值变为 0,它指向数组中的值 '17'。我想知道为什么会这样?

非常感谢!

【问题讨论】:

标签: c


【解决方案1】:

对于在没有static 的函数内定义的对象,没有默认值。它们的初始值是不确定的,通常情况下,使用一个而不设置值的行为是不确定的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 2015-06-13
    • 1970-01-01
    • 1970-01-01
    • 2010-10-01
    • 2021-06-01
    • 1970-01-01
    相关资源
    最近更新 更多