In your example of a variable length array, even though you set the size with a random number, you don't actually exceed the original length you specify. So :-
int stackArray[COUNT];
and
int stackArray[rand()];
are the same at runtime. To demonstrate a variable length array shouldn't you assign a value to the array passed the end of the array when it is setup? like in the following code :-
#include
#include
#define COUNT 5
main()
{
srand(time(NULL));
int stackArray[COUNT];
int i;
for(i=0; i< COUNT;i++){
stackArray[i] = rand();
}
for(i=0;i
In a version C that does not support variable length arrays as soon as you try to assign a value in this case to stackArray slot 6 it would crash with a "Segmentation fault"
by Martin — Oct 17
In your example of a variable length array, even though you set the size with a random number, you don't actually exceed the original length you specify. So :-
int stackArray[COUNT];
and
int stackArray[rand()];
are the same at runtime. To demonstrate a variable length array shouldn't you assign a value to the array passed the end of the array when it is setup? like in the following code :-
#include
#include
#define COUNT 5
main()
{
srand(time(NULL));
int stackArray[COUNT];
int i;
for(i=0; i< COUNT;i++){
stackArray[i] = rand();
}
for(i=0;i
In a version C that does not support variable length arrays as soon as you try to assign a value in this case to stackArray slot 6 it would crash with a "Segmentation fault"
Your thoughts,
Martin