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
1 answer
how to convert a 2d array which is globally available to a malloc array(which can be passed as a parameter)
I want to change my globally available 2d array to a malloc array and pass it to the following function
I have this 2d array as a global variable
char grid[ROW][COLUMN];
I want to pass it to this functionas a parameter, but using a malloc…

david
- 3
- 4
0
votes
4 answers
How to terminate variable length array when all values are valid?
I'm passing an array of single-precision floating point values to a function in C. The function has no knowledge of the size of the array and I'd like to keep it that way, primarily because while the underlying array is of course fixed-length I…

CHollman82
- 576
- 1
- 8
- 28
0
votes
1 answer
Creating 2 (or 3?) dimensional array of string in C
I want to create an array of string like:
{{"zero","zero"},
{"zero","one"},
{"one","zero"},
{"one","one"}}
If I am not wrong I need 3D array. How can I create it with using dynamic memory allocation and how to return it from function? I mean how is…
user7385966
0
votes
1 answer
ISO C++ forbids variable length array 'arrayz' [-Wvla], Tried already on a c++ online gdb compiler and it runs fine
I am wondering why the following program produces this error. I have tried on the online gdb compiler and it works fine. I have searched it online and some recommended to use vector instead of array, but i can't since i am required to use array…

piacevole
- 13
- 1
0
votes
0 answers
How can I store different bit lengths in a file?
I have a problem with my code. I want to store numbers from 0 to 127 in bits, but I don't want to waste a number of bits as 0s in the beginning of the number, for some numbers.
For example, storing 15 would take 4 bits. I don't want to waste another…

Cute Boy
- 1
- 1
0
votes
1 answer
C++ examples where dynamic array is required instead of static array
I am trying to understand the difference between static and dynamic arrays in C++ and I can not think of a case where a static array would not do the trick.
I am considering a static array that would be declared this way:
int N=10;
int…

Mai Kar
- 138
- 1
- 3
- 18
0
votes
1 answer
variable-length array in struct with TI compiler in C (socket programming)
I'm writing code that dealing with data received from udp in application layer.
This is the function prototype used for receiving data from udp
int my_recv_UDP(int s,
void* mem,
int len,
struct…

Andy Lin
- 397
- 1
- 2
- 21
0
votes
3 answers
Number of Variables in an array
I have a code;
x = np.linspace(0, 12, 200, False, True, None)
when I print x, I get;
(array([ 0. , 0.06, 0.12, 0.18, 0.24, 0.3 , 0.36, 0.42, 0.48,
0.54, 0.6 , 0.66, 0.72, 0.78, 0.84, 0.9 , 0.96, 1.02,
1.08, 1.14,…

JuhBuh
- 9
- 1
0
votes
4 answers
Define array globally with variable parameter in C
Here's the code:
int EdgeCount = 0;
int numOfEdges = 0;
void addEdge() {
// some code
numOfEdges++;
}
int EdgeWeightArray[numOfEdges]; // error
I want that global array with variable parameters to use it later but I couldn't do that…

umair mughal
- 66
- 7
0
votes
5 answers
Arrays created in functions,compile time or run time?
When we create an array on the stack most compilers will want to know the size of the array which will be determined at compile time so generally we can't get a user to enter the size of the array from standard input,but what if we are calling a…

strikeforcefan2013
- 49
- 8
0
votes
1 answer
Just for kicks: Creating/deep-copying multidimensional arrays in JavaScript and accounting for variable length?
I volunteer teaching coding to young girls to code and one of the more advanced ones was trying to use a 2D array for her JavaScript project, but was struggling with the concept of multidimensional arrays. I started putting together a tutorial on…

Allison
- 1,925
- 1
- 18
- 25
0
votes
0 answers
Nested for loop saving last input not whole input
I'm back again with that C question heh. So I'm trying to get the user to input a whole 2d array (size, values, everything), with VLA arrays (im using the latest compiler). Everything is fine up until I get the nested for loop, then it saves the…

Tcranmer
- 29
- 1
- 10
0
votes
1 answer
What is an expression of VLA type?
I was trying to understand the working of sizeof operator and I came across this
question. Following is the code from that question
#include
int main() {
int i = 0;
int a[i];
printf("%zu\n",sizeof(a[i++]));
…

mightyWOZ
- 7,946
- 3
- 29
- 46
0
votes
3 answers
Can't get length of array/object in an Object of Javascript
box = {
curBox: 0,
boxes: document.getElementsByClassName('box'),
size: this.boxes.length, //this one won't work
orSize: Object.keys(this.boxes).length, //as well as this one
preBox: function() {
curBox -= 1
},
nexBox:…

Star Light
- 154
- 2
- 8
- 19
0
votes
4 answers
Is there a VLAs (variable length arrays) support workaround for VS2017?
So simple code like:
int n;
cin >> n;
int s[n], p[2*(n-1)][3];
I have to translate to:
int n;
cin >> n;
vector s(n, 0);
vector> p(2 * (n - 1), vector(3));
I would like to see something like:
int n;
cin >> n;
mat s(n),…

DuckQueen
- 772
- 10
- 62
- 134