What is the default value of members of a char array in C?

后端 未结 4 1282
执念已碎
执念已碎 2021-01-02 19:14

Say I create a char array, and I assume the char array is empty. If I check the value of the first element in the array (arr[0]), what would be the

4条回答
  •  天命终不由人
    2021-01-02 19:49

    when initiate array. your are allocating a static memory. and then you will get the values of allocated memory so it's random values

    if you want set the whole array to 0 then (According to Hunter McMillen Remark)

    char arr[size] = { 0 }
    

    or use memset() function

    memset(arr,0,sizeof_your_arr);
    

提交回复
热议问题