在 C 中,未初始化数组中 char 的默认值是多少? [英] What is the default value of a char in an uninitialized array, in C?

查看:70
本文介绍了在 C 中,未初始化数组中 char 的默认值是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于以下声明:

char inputBuffer[12];

数组中任一字符的默认值是多少?我有兴趣知道这一点,因为如果我想在任何时候清除数组中的某个位置,我需要知道要赋予它什么值.

What is the default value of either char within the array? I'm interested in knowing this because if at any time I want to clear a position in the array, I need to know what value to give it.

推荐答案

数组元素具有不确定的值,除非数组在文件范围内定义或具有 static 存储类说明符,然后数组元素被初始化为 0.

The array elements have indeterminate value except if the array it is defined at file-scope or have static storage-class specifier then the array elements are initialized to 0.

 #include <stdio.h>

 char inputBuffer1[12];          // elements initialized to 0
 static char inputBuffer2[12];   // elements initialized to 0

 void foo(void)
 {
     char inputBuffer3[12];         // elements have indeterminate value!
     static char inputBuffer4[12];  // elements initialized to 0
 }

这篇关于在 C 中,未初始化数组中 char 的默认值是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆