size of array in c

后端 未结 6 1325
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 20:59

a simple question that bugs me. Say I have an array defined in main like so int arr[5]. Now, if I\'m still inside main and I set int i = sizeof(arr)/sizeo

6条回答
  •  悲&欢浪女
    2020-12-01 21:47

    This is because arr is now a pointer and it could point to a single int or an array of 1000 ints the function just does not know. You will have to pass the size of the array into the function.

    In main arr is declared as an int[5] and so the size can be calculated by the compiler.

提交回复
热议问题