Questions tagged [variable-length-array]

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.

413 questions
0
votes
1 answer

Posting data from variable length 2 dimensional array

I am having some issues with posting data from a 2 dimensional array and echoing them. I have read several topics and tutorials on multidimensional array, but most of them used fixed length of arrays as examples. In my case both the dimensions of…
sansam
  • 57
  • 10
0
votes
3 answers

How to initialize multidimentional array in C Programming

I am getting error when i am running this code int row1=2,col1=2; int mat1[row1][col1]= { {1,5}, {4,6} }; What is wrong with this code?? IDE: CodeBlocks error: variable-sized object may not be initialized|
user8965395
0
votes
2 answers

Dynamic Arrays and Static Arrays Compile Time or Runtime?

I understand the basic concept of Static Arrays and dynamic arrays. The main difference between these two are one(Static Array) allocates memory at compile time, and the other at runtime. However, we can create static array whose size would be the…
0
votes
1 answer

Bug in jQuery array (i), when adding a +1 to a negative value

I guess I'm fighting a bug. I build a small carousel in jquery. It's more some boxs stacked on each other, that will change their z-index (jquery.css) when my user clicks the next and prev arrows. So far so good, the carousel is connected with…
user6818018
0
votes
2 answers

Variable length string duplication in Python

The following short python script: var1 = '7f0000000000000000000000000000000000000000000000000000000000000002' var2 = '01' output = 'evm --code ' + var1 + var1 + var2 + ' run' print(output) Is capable of generating the following string: evm…
smatthewenglish
  • 2,831
  • 4
  • 36
  • 72
0
votes
2 answers

Alert popping up even if no selection is made in the table

I've a bootstrap modal which contains a table of users. I can select a user from the table and on clicking 'save', the details of selected user is displayed and I get an alert stating 'Data saved successfully!'. The alert is at the end of the…
0
votes
2 answers

how to pass dynamic 2d array to a function without using the pointers?

I tried this but it is not working ! can any one help me please this is very important :( #include using namespace std; int a[100][100]; void read(int a[][100],int n) { int i,j; for(i=0;i
0
votes
2 answers

Array[0] is changing while entering the "for" loop, can't figure out why

I'm doing a challenge on HackerRank got the method figured out but there's a slight error I cannot figure out. Further information if needed is https://www.hackerrank.com/challenges/sparse-arrays Basically I only have a problem with arr[0]. It's…
Rand
  • 87
  • 2
  • 9
0
votes
4 answers

Returning a variable length array from a function

The following function "increment" add 1 to a number represented as an array. int* increment(int array[], int size, int *sizeLen) { int temp[size+1]; int carry = 0; carry = (array[size-1]+1)/10; temp[size] = (array[size-1]+1)%10; …
eagle
  • 35
  • 1
  • 8
0
votes
2 answers

How to create variable length array on heap?

I used C's variable length array to implement an algorithm: int matrix[rows][cols]; I managed to test that this does fail for ridiculous dimensions. Is there a way to allocate this matrix on heap instead of stack? Otherwise I'll have to rewrite…
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
0
votes
2 answers

Is creating array with a variable number of elements possible?

Whenever I need to create an array with a number of elements not known until execution time I do this. int n, i; printf("Number of elements: "); scanf("%d", &n); int myArray[n]; for(i = 0; i < n; i++) myArray[i] = 0; However I've been told by 3…
user3050314
0
votes
3 answers

From where do the initial values of the variable length array (VLA) in [c] come?

example c code: #include int main (int argc, char** args) { int k = 8; int sendbuffer[k]; // VLA for (int n = 0; n < k; n++) { printf("sendbuffer[%i]: %i \n", n, sendbuffer[n]); } return 0; } example…
illnr
  • 750
  • 9
  • 13
0
votes
6 answers

When array size determined at run time , is it allocating from stack or heap?

In the below code,is the arr[n] is allocated from stack or heap? I am confused since in general the array size is determined at compile time. How the below code working ? #include int main(){ int n; scanf("%d",&n); int arr[n]; …
Vignesh
  • 37
  • 7
0
votes
1 answer

Variable length array storage space in c/c++

Below is my simple code snippet. #include using namespace std; bool testAllocArray(const unsigned int length) { char array[length]; //--------------------------(1) return true; } int main(int argc, char** argv) { …
Suresh
  • 27
  • 1
  • 8
0
votes
3 answers

variable length two dimensional array c++

Why is this code compiling successfully, without any warning: int m,n; cin >> m >> n; int arr[m][n]; [compiled with MinGW with Code::Blocks] Shouldn't atleast one of m or n must be constant at compile-time ?? I've seen variable length arrays…