Home > Back-end >  Temporary variables within the function into the parameter as a function of the array length is what
Temporary variables within the function into the parameter as a function of the array length is what

Time:09-30

Func (int len... )
{
An int array (len)={0};
}
Because of the participation and the array itself are saved on the stack, so the redistribution when the array length have been confirmed in len, so there will be no problem, is it

If memory function need recommend wrote above, or below wrote

Func (int len... )
{
Int * array=(int *) malloc (sizeof (int) * len);
}

CodePudding user response:

Array length must be a compile time can be determined,
Unless it is support variable-length array compiler,

CodePudding user response:

The first is problematic, because len uncertain length, so the compiler doesn't know for how long array, it apply for
The second is no problem, because is a dynamic application, is in the calling function to malloc application space,

CodePudding user response:

First there is a problem, syntax error
Or
Array [len]=10;
Or
An int array [100]={10};

Int array (len)={10} not write so much

CodePudding user response:

C99 has a vla features to support you with variable as the array size

CodePudding user response:

But the VLA cannot initialize
The first piece of code so you should still wrong

CodePudding user response:

This to is not saved on the stack, starting from the C99 introduced VLA, so an int array (len) legal, but cannot use {} initialization, the first piece of code can be compiled through, shows that the compiler is a c + +, and not the kind of archaic times ~ ~ ~

CodePudding user response:

reference 3 floor truth is right or wrong response:
first there is a problem, syntax error
Or
Array [len]=10;
Or
An int array [100]={10};

An int array (len)={10} there is no such written

1 piece of code is no problem, I compile and run, and the second result is perfect

CodePudding user response:

reference 2 building self-confidence boy reply:
first is problematic, because len uncertain length, so the compiler don't know how long for it to apply for an array,
The second is no problem, because is a dynamic application, is in the calling function to malloc application space,
1 code is no problem, I compile and run, and the second result is perfect

CodePudding user response:

refer to 6th floor coo135 response:
this to is not saved on the stack, starting from the C99 introduced VLA, so an int array (len) legal, but cannot use {} initialization, the first piece of code can be compiled through, shows that the compiler is a c + +, and not the kind of archaic times ~ ~ ~
compile and run the right, I tried, but can't really={} initialization, why cannot be initialized

CodePudding user response:

refer to 7th floor adaizhuadaizhu response:
Quote: the truth is right or wrong reference 3 floor response:

First there is a problem, syntax error
Or
Array [len]=10;
Or
An int array [100]={10};

An int array (len)={10} there is no such written

1 piece of code is no problem, I compile and run, and the second result is exactly the same

Your compiler doesn't conform to the standard

CodePudding user response:

refer to the eighth floor adaizhuadaizhu response:
Quote: refer to the second floor confident boy reply:

The first is problematic, because len uncertain length, so the compiler doesn't know for how long array, it apply for
The second is no problem, because is a dynamic application, is in the calling function to malloc application space,
1 code is no problem, I compile and run, and the second result is exactly the same

That no problem, if the first one ask before calling, len?

CodePudding user response:

references to the tenth floor truth is right or wrong response:
Quote: refer to 7th floor adaizhuadaizhu response:

Quote: refer to the third floor truth is right or wrong response:

First there is a problem, syntax error
Or
Array [len]=10;
Or
An int array [100]={10};

An int array (len)={10} there is no such written

1 piece of code is no problem, I compile and run, and the second result is exactly the same

Your compiler doesn't conform to the standard

Leetcode is normal operation

CodePudding user response:

If you want to correct, unless he supports vla
  • Related