Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Discussion on array length in C language
Discussion on array length in C language
You can use the function of C itself! !

Firstly, it is pointed out that the length of an array is given at the time of definition, but the length at the time of definition may not be used up, and there may be a lot of unused space, so the concept of actual length comes into being.

For example: int s [10];

s[ 10]={ 1,2,3,4,5,6 };

The length of the integer array S is defined as 10, but only 6 is assigned when the initial value is assigned, so 6 is the actual length of the array! !

With regard to the solution of the actual length of the integer array, you can set the counter variable at the time of input, and automatically add one for each input number.

Regarding the length and actual length of the character array, when it is also defined; We often use the actual length: its solution can be found by strlen () function;

For example: char s [60];

CIN & gt; & gts;

cout & lt& ltstrlen(s);

Do it! !

If the input is: abcdefghj

Input quantity: 9