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
Weird output with a variable length array?
I am breaking my head on this but cannot proceed so please help.
Working on a programming assignment:
INPUT:
First line contains a value N representing the dimension of the input matrix, followed by N lines, each line representing a row of the…

user138645
- 772
- 1
- 7
- 18
0
votes
1 answer
How to expand a one-dimensional array at runtime in C?
I'm learning C language and I have a question about dynamic memory allocation.
Consider that I have a program that the user must enter numbers or typing the letter "E" to exit the program.
The numbers that the user enter must be stored in a…

regisls
- 529
- 6
- 23
0
votes
0 answers
Plotting data sets of different lengths from a struct - avoid padding
I hope this is a simple enough question, but I am a beginner and haven't managed it on my own after several sessions.
I have a 1x29 struct of financial market data with 8 fields: stock_market.
the first field is the date
As you can see, not all the…

n1k31t4
- 2,745
- 2
- 24
- 38
0
votes
1 answer
pseudocode array length or size of affect its running time?
I am asked to write pseudocode and analyze the running time of my function.
I am given 2 descending sorted arrays, and 1 integer k
and then asked to find out the kth largest number in the union of the 2 arrays.
I have run my code, as the assignment…

user3247413
- 11
- 2
- 5
0
votes
1 answer
Shell Script - How to create variables with specific length?
I'm new on shell scripting, and I need a help on this.
How could I create an output file delimited by variable strings? I mean, each variable has an specific length, for example:
variable1 (char 10)
variable2 (char 5)
variable3 (char 4)
variable4…

Lizarb
- 3
- 2
0
votes
2 answers
GCC allowing arrays to be initialized with variable length
GCC compiles the following function
void f(int i)
{
int a[i];
}
I was under the impression that you can only initialize arrays with constant length. Is this supposed to compile, and will it do what I expect it to?

tomKPZ
- 827
- 1
- 10
- 17
0
votes
1 answer
Compile- vs run-time const variable assignment and allocation of vlas in C++
I was working on a template function with non-type parameters (to avoid dynamic allocation of arrays) when a number of questions arose. My first question regards compile-time variable assignment. This arose from the following attempts at calls to…

glinka
- 337
- 3
- 13
0
votes
1 answer
Perl - Splitting a string
I'm doing an Array that contents each word of a phrase. When I try to split it and print the length then the console gives me an enormous number such as 111039391231319239188238139123919232913123... (more lines)
why?
Here's my code:
$mynames =…

Marc Ortiz
- 2,242
- 5
- 27
- 46
0
votes
1 answer
C++ : Variable Length Array
How does Variable Length arrays (VLA) take space in memory?
I have observed that VLAs do not take continuous memory space, can anyone please confirm the same??
void func(const IplImage *imgSrc, IplImage *imgDest)
{
uchar *data = (uchar…

techbull
- 118
- 2
- 16
0
votes
3 answers
VLA's memory available under gcc
As malloc returns NULL, is there any way to detect that there is insufficient memory on the stack using VLA's?

David Ranieri
- 39,972
- 7
- 52
- 94
0
votes
4 answers
Scanf array limit in C?
I have some little error in C:
Error: expression must have a constant value
I know, that's mean that my limit must have a constant value, but how i can to solve that when i have this situation?
printf("Type limit: ");
scanf("%i",&limit);
int…

user1814358
- 619
- 3
- 8
- 17
0
votes
2 answers
Declaring variable length array in a class
folks. Here's my piece of code:
class Solar_system
{
public:
Solar_system()
{
planet_no = 5;
}
int planet_no;
int planet[planet_no];
};
Error given: invalid use of non-static data member Solar_system::planet_no…

Andrei Albu
- 11
- 3
0
votes
1 answer
Default values in Column of type variable length array Postgresql
My question is how can I set the default values for a certain index in variable length array column. I am trying to set the value of one of the positions to default to string 'false'.
Reason being is I want to be able to have a where clause on a…

parchambeau
- 1,141
- 9
- 34
- 56
0
votes
1 answer
Dynamically-Allocated Stack Memory with Class Scope
Several compilers support extensions to C++ whereby one can dynamically allocate memory on the stack. For instance, g++ supports alloca() as well as VLAs. All of these extensions come with the caveat that the dynamically-allocated memory is…

void-pointer
- 14,247
- 11
- 43
- 61
-1
votes
2 answers
When to use Variable Length Array (VLA)?
malloc is slow and allocates on the heap. Good for large objects or
objects that need to get their lifetime extended beyond the function
where they are created.
static allocation is on the stack. Allocation baked in by compiler
so essentially free…

Lolo
- 3,935
- 5
- 40
- 50