The programming language I first touched was Ruby or JavaScript, so the C language I started recently is just fresh and interesting. There is no such thing as a length
method.
TL;DR
main.c
#include <stdio.h>
int main()
{
const size_t NUM = 100;
int numbers[NUM];
for (size_t i = 0; i < NUM; ++i)
numbers[i] = i;
int length = sizeof(numbers) / sizeof(numbers[0]);
printf("length of 'numbers' is: %d\n", length);
}
Unfortunately, there is no method to calculate the number of elements in an array in C language, so it seems that there is no choice but to calculate total number of bytes in the array / number of bytes per array
. It seems that the value of the pointer can be obtained no matter what, but I haven't studied about that yet, so next time.
Recommended Posts