Just a new programmer here.
I was experimenting with size_t and sizeof, specifically using them to find the size of an array, cause I was trying to make an array with the number of indexes be changeable.
Code:
int main() {
int index = 0;
printf("Enter size of an array: ");
scanf("%d", &index);
int MyArray[index];
size_t capacity = sizeof(MyArray)/sizeof(MyArray[0]);
printf("\nThe length of your array is: %llu", capacity);
return 0;
}
And if you look at the printf statement, you can see that I used a format specifier which is %llu for long long unsigned int because (if I'm right) it was the data type of size_t.
But then it gives me multiple warnings like:
warning: unknown conversion type character 'l' in format [-Wformat=]|
warning: too many arguments for format [-Wformat-extra-args]|
Clearly that is not right. Some C implementations may use
long long unsigned intforsize_t, but yours does not.The C standard specifies a
printfformat flag for thesize_ttype,z, so%zuis a correct conversion specifier to use forsize_tin any C implementation.