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
3 answers

Expression must have a constant value problem

I used C in Visual Studio to make a code for a user to input size of array. The code does not work in Visual Studio and gives errors. But on a site like replit it works. I don't understand what to do to make it work in Visual Studio. #include…
0
votes
1 answer

How to create user define array structure of n size in c language

I want to create a 'n' size of array structure but I don't know how to do it. I always create static like this typedef struct { int id; char name[25]; char dob[11]; }info; info student[5]; here i want it info student[n] but it doesn't work…
0
votes
1 answer

The difference between g++ and clang++'s handling of VLAs definition and initialization in c++

The source code as follows: using namespace std; int main() { int m = 4; int arr[m] = {1, 2, 3, 4}; printf("%d\n", arr[2]); return 0; } When I compile with g++, it compiles successfully as an executable. But when I…
YoLo22
  • 1
0
votes
1 answer

Why does the "size_of_array" template fucntion does not work with int a[n] (size defined at runtime) while it works fine with int a[4]?

template int tell_me_size(T (&) [n]){ return n; } this code works fine with int a[4]; cout<< tell_me_size(a)<>n; int a[n]; cout<< tell_me_size(a)<
0
votes
1 answer

VBA - Reading a text file, splitting it into array and printing it back in VBA Word

Hello I would like to take my txt file containing string of data, split it into array by line. However, I am not able to either input data to array correctly or I have problem with the function GetArrLength. I am pretty new to VBA and can't figure…
Jahelnice
  • 25
  • 6
0
votes
2 answers

static memory allocation like dynamic memory allocation

Code: int r, c; cin >> r >> c; int matrix[r][c]; I don't understand the idea behind runtime allocation. The aim is to allocate memory during runtime but in the above section of code we are doing the same. When this part of code is run, the inputs…
0
votes
0 answers

How to Use A[n][n] in function?

I am studying CSAPP and the book says we can use this following code : #include int var_ele(size_t n, int A[n][n], size_t i, size_t j) { return A[i][j]; } but I cannot compile this. The book says in the past we need to write like this…
dubugger
  • 89
  • 6
0
votes
3 answers

Create a 2-d array by taking input from the user. Write a display function to print the content of this 2-d array on the screen?

The code I have written is not giving the input that are the marks been provided to it by the user , insted of that it is printing all random garbage values. Kindly help to solve the problem. #include void display(int number_1, int…
0
votes
5 answers

Dynamic memory allocation in C for variable length arrays

When is it better to instantiate a variable length array with calloc vs. "normal" array declaration in C? Consider the 'array declaration' approach: #include #include int main(int argc, char *argv[]) { int n =…
rlh2
  • 1,039
  • 2
  • 9
  • 16
0
votes
1 answer

Why is this VLA (variable-length array) definition unreliable?

Why doesn't this code defining and using a VLA (variable-length array) work reliably? #include int main(void) { int n; double vla[n]; if (scanf("%d", &n) != 1) return 1; for (int i = 0; i < n; i++) { …
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
0
votes
0 answers

How to get length of updated array using property in JS?

I created a variable to hold the total number of elements in the array using myArray.length. Then I use myArray.push() to add an element to the array. the original array has 3 elements, so the .length returns 3, which is correct. But when I added an…
Qiyuan Liu
  • 27
  • 3
0
votes
1 answer

How can i get the number of docs located in specific collection by only paying for one query process

Of course, I can know how to get the number of docs by the following code: handledocsNumber(){ Future>> number = FirebaseFirestore.instance.collection("users").get(); number.then((value) { int…
0
votes
2 answers

Print out the length of an array in JAVA

I need to program a lottery simulator and basically everything works fine but I have one small problem at the end of the problem. There are 2 Arrays(i need to work without Array Lists) which get compared. The generated winning numbers and the…
Bela
  • 1
  • 1
0
votes
1 answer

can we declare a variable inside an array

#include int main () { int size,i; int arr[size]; printf ("Enter size of array\n"); scanf ("%d",arr[size]); for (i=0; i<=size; i++) { printf ("%d", arr[size]); } return 0; }
0
votes
1 answer

how fix this error:Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'length')

I am creating a website loading gltf 3d models.I want to load more models using loop. const loader = new GLTFLoader() //.setPath( 'models/gltf/DamagedHelmet/glTF/' ); .setPath( 'resources/' ); const resourceData = ["Learning Bee1","Learning…
Nirodha Lakmali
  • 105
  • 1
  • 1
  • 10