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
only read the length of variable-length array without reading the elements in hdf5
Is it possible to do this?
I have an array containing Nvl HDF5-variable-length-arrays already written to a hdf5 file. I can read in the entire data by (the following snippet is in c++, but answers using the C version of hdf5 API are equally…

Kambrian
- 329
- 2
- 7
0
votes
1 answer
Storing a 3D VLA on heap
I need to store an array on heap since I got a seg fault when running the program, due to it being too large. Normally this would be easy, but in this case it is a multidimensional array (3D specifically) and it's a variable length array too.
I…

Joshua D'Agostino
- 39
- 4
- 10
0
votes
1 answer
Segfault when assigning token pointer (from strtok) to pointer element of 2d VLA of structs
I'm attempting to parse a csv file and store those values in an 2d VLA.
The first codeblock shows the two calls I have to the function TokenizeLine which very simply uses strtok to break the line apart and assign the token to the appropriate cell in…

J2R5M3
- 445
- 3
- 9
0
votes
1 answer
Why can't we specify a variable size when declaring a static array?
Through dynamic memory allocation, the following the code works perfectly.
int *ptr;
int size1;
cin >> size1;
ptr = new int[size1];
In static memory allocation, I get the following error: array bound is not an integer constant before ']'…

Moiz Sajid
- 644
- 1
- 10
- 20
0
votes
2 answers
How to pass a dynamic 2-D array to a function in C++
I am trying to pass a dynamic 2-D array to a function and it gives an error. I tried explicitly providing the array dimensions and it worked but dynamic is not working, any pointers (pun not intended)
#include
#include
using…

Rahul Kadukar
- 858
- 3
- 15
- 35
0
votes
1 answer
Why arbitrary expressions can't be used as an array size, e.g. int[0,1]?
Ignoring static and * (for an omitted size) in between the [] brackets, the syntax for an array declarator is (from C99 TC3 (n1256) 6.7.5 p1; C11 (n1570) 6.7.6 p1):
direct-declarator:
direct-declarator [ type-qualifier-listopt…

mafso
- 5,433
- 2
- 19
- 40
0
votes
1 answer
Return an Array Length in Livecode
I have an array with four string values "Hello","All","of", and "you". I need to display the total length of the array which is 4 and display it to label text. How to do that?

Mai
- 363
- 3
- 16
0
votes
0 answers
Python Code for plot. Receiving a message that I have 1 less Y value
from scitools.std import *
t = []
v = []
infile = open('running.txt', 'r')
for line in infile:
tnext, vnext = line.strip().split(',')
t.append(float(tnext))
v.append(float(vnext))
infile.close()
a = []
for i in range(len(t)-1):
…
0
votes
1 answer
C++ Passing Dynamic Array Determined by Parameter
This function has been asked a few times on here but I am interested in a particular case. Is it possible to have the size of the array passed defined by an additional argument?
As an example, let's say I want a function to print a 2D array. …

cdeterman
- 19,630
- 7
- 76
- 100
0
votes
2 answers
How to store variable length arrays?
I want to store an array which changes its size in each iteration of a for loop.
For example,
for y=1:100
for x=1:50
.
.
ms(:,x,y) = ans;
.
.
end
end
The 'ans' is a row vector which changes its size in each iteration of y.
How can…

Kave
- 1
- 1
0
votes
1 answer
Passing variable defining the size of a 2D array's elements
I'm working on some passing of arrays in C++. The following works, provided I define the array with numbers such as:
gen0[6][7].
But, I cannot call the method where I send a variable as my size parameters. I realize that I probably need to…

user3571353
- 11
- 1
0
votes
1 answer
How to get VC++ to access a pointer as a 2D array
I'm doing a little graphics programming and I have a two dimentional array (that varies in size during program execution) that I store using openGL.
So when I go to access it, all I get is a void pointer back.
To make the logic easier, I want the…

Hashbrown
- 12,091
- 8
- 72
- 95
0
votes
0 answers
C++ initialize array size using constant variable
I noticed that G++ compiler does permit initializing an array like this:
vector > partition(string s) {
const int len = s.size();
vector > subPalins[len+1] ;
subPalins[0] = vector >();
…

eaglesky
- 730
- 2
- 13
- 28
0
votes
1 answer
Static array of chars with dynamic size
I'm creating static array of chars which size is defined runtime. And I'm not getting compilation errors. How is this possible?
Here is my example:
void f(const string& val) {
char valBuf[val.size() + 1]; strcpy(valBuf, val.c_str());
cout <<…

Heghine
- 435
- 3
- 15
0
votes
2 answers
C accessing a variable length array
I need to access a variable length array i have created on the first line reading from a file.
In order to access the array for when i am reading the following lines i would need to initialize it before line 1 is read out side of my conditional…

Michael Kent
- 383
- 3
- 17