A variable length array is an array in C99 and other languages whose size is unknown at compile time; instead, it's determined at runtime.
Questions tagged [variable-length-array]
413 questions
0
votes
2 answers
Static Allocation - C language
As far as I know, the C compiler (I am using GCC 6) will scan the code in order to:
Finding syntax issues;
Allocating memory to the program (Static allocation concept);
So why does this code work?
int main(){
int integers_amount; // each int…

Matheus Minguini
- 147
- 1
- 14
0
votes
1 answer
Why does this code crash when accessing variable-length-array element?
If I want to give 10 elements, I scan how_many as 10.
But as soon as I enter the third value, the program crashes and returns some long negative value. I don't know where is the problem.
int main()
{
int how_many,k;
int data[how_many];
…
0
votes
1 answer
how to get length of array in Native script (vueJS)
I would like to know how I can get the length of my array in Native script /vue JS?
My code :
export default {
data: () => {
return {
i: 0,
log: [],
img:[
"~/Pictures/home.png",
…
0
votes
1 answer
When and How the pointer arithmetic evaluate?
I always took pointer arithmetic for granted. But some times it bugs me, what compiler exactly does, and when do they get evaluated? Consider the program below:
#include
#include
int prng(void);
int main()
{
int x =…

m0hithreddy
- 1,752
- 1
- 10
- 17
0
votes
1 answer
A graceful or at least workable way of using and accepting literal carray constants of varying size with overloaded methods and operators
So I have this test case and am trying to no have to make one million operator overloads or handle overload collisions or complexity. I want to be able to handle literal array constants with operator overloads. This is sort of a requirement to…

Ismael Harun
- 143
- 2
- 7
0
votes
1 answer
Why is this code considered a VLA even though it uses an int?
I thought that I understood what a VLA is, until I saw a question asked here about the difference between dynamic memory allocation vs variable length arrays. So I don't have any problem, at least for now, with dynamic memory allocations, but what I…

KMG
- 1,433
- 1
- 8
- 19
0
votes
5 answers
Why for loop never ends?
int ln;
printf("how many letters are your name?\n");
scanf("%d", &ln);
printf("Ok...enter your name by characters: \n");
char name[ln];
for (int i = 0; i<=ln; i++){
scanf("%s", &name[i]);
}
This code should transform a name in the array but the…

Jack_01
- 17
- 3
0
votes
1 answer
Program received signal SIGSEGV, Segmentation fault when trying to allocate a multi-length 3D array
I'm a beginner to Fortran and trying to solve a problem to group some datasets which has the same distance to a point. I'm trying to create a 3D array range_data with different length (n,5,120) (n varies). I want to group 5 1D-arrays URS PROB ix iy…

PIZGY
- 1
0
votes
0 answers
Working with variable dimension tensors in tensorflow
I want to build a tensor placeholder, features with dimension, say (10, a, a). Such that features[i, :, :] can be an arbitrary square tensor. As an instance, features[0. :, :] may be of dimension 5*5, and features[1, :, :] can be of dimension 8*8 at…
0
votes
2 answers
ISO C90 forbids variable length array [-Werror=vla]
So i created a structure called product and i wanted to sort an array with that structure type based in a component of that structure called price, and to do that i copied a merged sort algorithm.
I altered it a bit to sort the array the way i…

Martimc.
- 53
- 1
- 6
0
votes
1 answer
How to import binary files into DolphinDB?
I have a binary file and I want to import it into DolphinDB. But the function readRecord! does not support importing a table with a field in type of STRING:
f.readRecord!(tb)
ERROR MESSAGE:
Read only object or object without ownership can't be…

Irene97
- 50
- 5
0
votes
3 answers
Why does defining this size variable as const result in memory being zeroed out? (godbolt example included)
Compiler Explorer Example: https://godbolt.org/z/AEv4Ci
This code
int main() {
const int Size = 16; <-- const
int arr1[Size];
int arr2[Size];
int arr3[Size];
for (auto I = 0; I < Size; ++I) {
arr3[I] = arr1[I] + arr2[I];
}
return…

rufiplz
- 3
- 1
0
votes
2 answers
i made a length() function in c and i want to put the number it returns into the size of an array,
but it isn't possible because I can't put a variable in the array size. ideas?
the function will check how many digits build the integer and will return that number
int intLength(int number)
{
for(int i=0;i

G0rdo1
- 73
- 1
- 1
- 6
0
votes
1 answer
Are gcc's dynamically-sized arrays effectively identical to standard arrays after declaration?
In standard C and C++ the address of an array is the array itself, and sizeof returns the size of the array, not the pointer. However, does gcc's extension of dynamically-sized arrays offer the same guarantee?
I tried this simple code:
#include…

Ken Y-N
- 14,644
- 21
- 71
- 114
0
votes
3 answers
Weird type assignment for array index in C++
Hi I have a sample program
#include
int main() {
int a = -5;
int arr[a];
std::cout << "Size of arr: " << sizeof(arr) << std::endl;
return 0;
}
Here I am getting the output of 17179869164.
My question is that the array…

Karthikgr
- 81
- 13