What is the default value of a char in an uninitialized array, in C?

前端 未结 2 1632
闹比i
闹比i 2021-01-03 04:49

Given the following declaration:

char inputBuffer[12];

What is the default value of either char within the array? I\'m interested in knowing thi

2条回答
  •  悲&欢浪女
    2021-01-03 05:16

    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 
    
     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
     }
    

提交回复
热议问题