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
-1
votes
1 answer
I want to convert integer into an array in C and this is my code and it kind of works
Im learning C right now and I've got this problem I want to convert the integer into an array my code works but the problem is that I declare the size of an array in the beginning and I want to make it so that it works for every integer…

Giorgi
- 13
- 2
-1
votes
2 answers
How do I solve this array problem in C language?
I have 2 arrays:
int element[3] = {0, 1, 2};
int quantity[3] = {2, 3, 4};
Now I want a result array that will have two zeros, three ones and four twos.
int result[2+3+4] = {0, 0, 1, 1, 1, 2, 2, 2, 2};
How do I do this using loop?

Min Bani Adam
- 23
- 4
-1
votes
2 answers
What is causing the segmentation fault in this code? Code is in C
I've been working in C lately and I've started working with arrays recently. Can you help me identify what's causing the issue here? I'm fairly certain the function inputArray is, but I cannot figure out why.
#include
void inputArray(int…

emcosokic
- 51
- 6
-1
votes
2 answers
this is the question "write a program in C to pass the reference of an array to a function & print that array" ,this is not giving the output ,why?
I got this question asked by one of my peer, as i don't know "C" that much, but still being a beginner i tried solving it, this is the
approach i used, but it is not giving the expected output.
According to the question, it should print the…

Karishma Singh
- 13
- 3
-1
votes
1 answer
C program for loop ended with a zero with unkown count
The question goes as follows:
Using a for loop ended with writing 0, compute sum of even numbers, sum of odd numbers,
I have no idea why my code isn't working:
#include
#include
int main() {
int i = 0, num[i], sum, even,…

Younis
- 13
- 1
-1
votes
1 answer
Why does array prints garbage values?
I have created a 2d array and initialized to 0 in C++.
int n;
cin>>n;
int ar[n][n]={0};
for(int i=0;i

RaKo
- 49
- 1
- 2
- 11
-1
votes
2 answers
How to get std array size in a constant expression?
Consider this code:
#include
#include
struct A {
std::array test;
void method() {
std::size_t duptest[test.size()] = {}; // error: variable-sized object may not be initialized
}
};
Godbolt…

AnArrayOfFunctions
- 3,452
- 2
- 29
- 66
-1
votes
1 answer
javascript nested array sort, based on variable-length inner rankings array
Outer array should be sorted based on the combination of rankings of each student's variable-length inner "tests" array, ascending. Here's a simplified version of the raw data.
[
{
"studentId": "A",
"tests": [
{
…

thoroughlyConfused
- 21
- 3
-1
votes
1 answer
Warning assignment makes integer from pointer without a cast . float findMeanLine(int n ,int my2DArray[][n]) , findMeanCol(int n ,int my2DArray[][n])
#include
#include
#include
#include
#include
void fillPin2D(int n ,int my2DArray[][n]);
void showPin2D(int n ,int my2DArray[][n]);
float…

Vasilis
- 1
-1
votes
1 answer
Getting errors when creating multi file program in c
I'm trying to create a large, multi-file program in C language but I get errors.
The program is actually a smart phone book that can perform multiple tasks like listing, adding, searching for, and deleting names.
For each of those tasks, I created a…

Moe Hasan
- 11
- 2
-1
votes
1 answer
"Variable-sized object may not be initialized" - what does this mean, and why am I getting this type of error?
vector commonChars(vector& words) {
int count[words.size()][26] = {};
//getting error
//error: variable-sized object may not be initialized
string ele;
vector result;
for(int s1=0; s1

Abhisek Ray
- 1
- 1
-1
votes
1 answer
How to create linked list of arrays in c
I want to create a linked list that contains variable-length array-like int A[n][n].
I tried to do it like this, but I'm getting the error Incomplete type is not allowed.
struct Node {
int A[n][n];
struct Node* next;
};
Is there any way to do…

anfjnlnl
- 63
- 7
-1
votes
1 answer
In Python why does the variable specified inside the loop has length 1 whereas the other outside the loop has its original length?
As declaring a variable1 inside for loop I have assigned some string to it>>>whereas given another variable2 .....when provided with the output it shows variable1 len is 1 and variable2 has 8 how does that work???
for variable1 in "something is…

Shailendra Sisodia
- 29
- 3
-1
votes
2 answers
Why does array with variable-sized work but not dynamic array?
First of all, I am new to programming and don't know what "variable-sized array" and "dynamic array" mean.
I am just using those words to describe my situation. Feel free to edit with correct nomenclature.
Now to the question, I have following…

EMS
- 104
- 1
- 6
-1
votes
1 answer
Angular Object length in something wrong showing 4 data and count is 5
Angular Object length in something wrong showing 4 data and count is 5 why this display 5 instead of 4 count i can't understand why below thing…

Darshan Malani
- 478
- 3
- 12