sizeof(arr)/sizeof(arr[0])
时间: 2023-09-30 22:02:16 浏览: 122
sizeof 操作符
This expression calculates the number of elements in an array called "arr". It works by dividing the total size of the array (in bytes) by the size of a single element (also in bytes). This gives the total number of elements in the array.
For example, if "arr" is an array of integers with 10 elements, then sizeof(arr) would return the total size of the array in bytes (which would depend on the size of an integer on the particular system), and sizeof(arr[0]) would return the size of a single integer element. Dividing these two values gives the number of elements in the array, which is 10 in this case.
阅读全文