Home > Back-end > C how to acquire the array elements' real 'number
C how to acquire the array elements' real 'number
Time:09-16
C code is as follows:
#include { Int arr [10]={0}; }
Define a named arr and can hold 10 integer array of data, part has been initialized values. But I want to know the number of actual element in the array, which is number 3 (1, 2, 3), how can I use code implementation.
CodePudding user response:
It might be a method ha: Initialization time assign special values (impossible to obtain values, such as you want to store is positive, negative, the initialization time assignment such as 1), the need to get the number of array elements, traversal, to know the actual number, The trouble is, every time to use arrays, need to be initialized.
CodePudding user response:
Only his record for you, you is the length of the actual 10, you took three inside, the rest of the default 0 useless,
CodePudding user response:
Oneself maintain a variable record how many elements are At first, how many of the array is initialized to how much Add an element is An element is less minus 1
CodePudding user response:
This is no interface, for defining such an array, in addition to the first three initialization, behind, which has not been initialized values default is 0. How many valid data array, the need to maintain and preserve,