How to calculate the array length in C language without first determining the array length? The answer is as follows

For an array whose length has not been determined in advance, and then assign a value to the array,
how to determine the length of the array? In the past, sizeof (array variable address)/sizeof (array variable type) was generally used to calculate.
After many computer verifications, it was found that this method is only effective for arrays whose array length is determined in advance, and has no effect on arrays whose array length is not determined in advance.
Later, I had a flash of inspiration and came up with the following method for your reference and learning.
Insert image description here
The running results are as follows. In fact, the array length is equal to i, and sizeof() is not needed for calculation.
operation result

Guess you like

Origin blog.csdn.net/weixin_43581878/article/details/105190658