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
-2
votes
2 answers
C++ filling in array with input from another
I'm just taking input for two arrays and manipulating the information. When I take input for both arrays it puts the information from the second into both arrays. In the code below I haven even commented out the input for the second array to see…
-2
votes
1 answer
What happens in compiler extensions that accept a user input as size of an array? Do they allocate memory to the array at runtime?
How does it internally work in case of compiler extensions? Will this still be called static compile time memory allocation?
int size;
cin>>size;
int arr[size];

My thoughts
- 13
- 4
-2
votes
1 answer
variable char size without malloc in C
does char myStr[varLength] work in C?
I have the following (code here):
int isVMin(char c){
return c == 'a' ||
c == 'e' ||
c == 'i' ||
c == 'o' ||
c == 'u' ||
c == 'y';
}
int…

serge
- 13,940
- 35
- 121
- 205
-2
votes
2 answers
I want to convert Vararg Integer to Vararg int?
The below code is working fine using Integer values for my variadic method. But I want to use "int" instead of "Integer".
Here is the code:
package JavaPracticeShuffler;
import java.util.ArrayList;
import java.util.List;
import…

JJJAAAVVVAAA
- 29
- 5
-2
votes
1 answer
Write a program that checks if a 2-D integer array is a square array, meaning, if its rows and columns are equal. My code is below
package Homeworks;
public class HomeWork85 {
public static void main(String[] args) {
int[][] a = {
{1,1,1,2},
{1,1,1},
{1,1,1}
};
int[][] b = {
{1,1,1,1},
{1,1,1,1},
…

ozz
- 3
- 3
-2
votes
2 answers
ArrayIndexOutOfBoundsException on array access
Good afternoon! I have to create 2 arrays. 1st one should create a random number (-10;10) if a user write 0, otherwise it should count using an entered formula; the 2nd array should write firstly elements from an array1 which have uneven number of…

Eli
- 51
- 5
-2
votes
1 answer
Passing pointer and then allocating variable length array to stack
Is it possible to allocate a variable length array to the stack in one function from another function?
One way that works is to just allocate the largest possible size up front, but I'm wondering if there is a way to avoid this.
void…

user3738579
- 33
- 4
-2
votes
2 answers
array size initialized dynamically example
I was having trouble understanding why
int n;
cin>>n;
int arr[n];
works. I was told that this code should not run because the value of 'n' could only be declared during runtime and therefore should not compile. I was also told that my 'n'…

coder666
- 41
- 7
-2
votes
1 answer
VLA works on gcc-4.9.2 but not on gcc-6.2.0
A very simple code to test VLA on gcc works fine on gcc-4.2.9 (Raspbian), but not on gcc-6.2.0 (Ubuntu). I am surprised. Though it compile without error, the output is not proper.
Code:
int len, i;
int test[len];
scanf("%d",&len);
…

CoderCha
- 1
-2
votes
3 answers
Is this actually dynamic memory allocation?
I have this code
int e;
scanf("%d",&e);
int ar[e];
is this dynamic allocation? It really looks like it is as I can allocate memory at run time.
I used this to get input from user for the number of elements and then filling it again by the user.

Hunar
- 67
- 7
-2
votes
1 answer
C compile error Variable-sized object may not be initialized with char * ptr[buflen]
Yes I did read these two posts.
C compile error: "Variable-sized object may not be initialized"
C error "variable-sized object may not be initialized"
My case is a bit different because I'm using char * ptr[buflen]. This is what I have tried:
char…

rocker
- 1
- 3
-3
votes
2 answers
Compilation error of Variable Length Array with GCC
How to make a compilation successful for a program with a variable length array?(currently, Showing error : Variable sized array). I am using gcc in linux. How to make compiler compatible to c99 standard ? PLease help me in this. THanks in advance.

Dhana Prakaash
- 21
- 2
-3
votes
1 answer
Implementaion of 2-D array in meomory using C
Actual ques - To find saddle point in a matrix.
My function call - find_saddle_point((Arr,rows);
My function prototype - void find_saddle_point(int *,int);
Initialization -
int rows , column ;
int Arr[rows][column];
Warning -
warning: passing…

Utkarsh Singh
- 39
- 6
-4
votes
2 answers
Why am I getting SIGFPE here?
I have made sure that in the statement i%a[i] == 0, that i and a[i] are between 1 and 100. But still, I get this error message!
#include
int main()
{
int n, m, x = 0, count = 0;
scanf("%d %d", &n, &m);
int a[n], b[m];
…

Yuv
- 61
- 6
-4
votes
1 answer
Why are variable length arrays in C++ overlapping on some sizes?
After providing an answer to a question here, I was testing this code that I edited and noticed some strange behavior:
#include
#define MAX 100
using namespace std;
int main()
{
int size = 0;
int array[MAX];
int i, j;
int…

AcidResin
- 134
- 2
- 12