Some example code to start the question:
#define FOO_COUNT 5
static const char *foo[] = {
"123",
"456",
"789",
"987",
"654"
};
The way this would normally be iterated over, as for one example, is the following:
int i = FOO_COUNT;
while (--i >= 0) {
printf("%s\n", foo[i]);
Is there anyway to do the above without explicitly having the human count the number 5? In the future I might add/remove elements and forget to update the size of the array, thus breaking my app.
Answer: No. It is not possible to declare an array without specifying the size. If at all you want to do that, then you can use ArrayList which is dynamic in nature.
int reqArraySize; printf("Enter the array size: "); scanf("%d", &reqArraySize); After this you may proceed with this interger input array size : for(i=0;i<reqArraySize;i++) scanf("%d",&arr[i]); Hope this helps you.
You can declare an array without a size specifier for the leftmost dimension in multiples cases: as a global variable with extern class storage (the array is defined elsewhere), as a function parameter: int main(int argc, char *argv[]) .
int[] integers; int j = 0; do { integers = new int[j + 1]; integers[j] = in. nextInt(); j++; } while((integers[j-1] >= 1) ||(integers[j-1]) <= 100); java.
int i = sizeof(foo)/sizeof(foo[0]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With