Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - In C language, I don't know how many elements in the array are output by using FOR loop.
In C language, I don't know how many elements in the array are output by using FOR loop.
If you don't know the number of elements in the array, it is usually an int array or a char array. See the following code implementation requirements:

# include & ltstdio.h & gt

Invalid? Master ()

{

int? num[]={ 1,2,3 };

Charles? str[]={'4 ',' 5 ',' 6 ' };

for(int? I = 0; I< sizeof (num)/sizeof (int); I++)//sizeof(num)/sizeof(int) calculation length

{

printf("%d?" ,num[I]);

}

puts(" ");

for(I = 0; I< sizeof (str)/sizeof (char); i++)

{

printf("%c? ,str[I]);

}

puts(" ");

} If it is a string array, you can use str[i]! =0 to determine whether it reaches the tail, so there is no such thing as the number of elements.