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
1 answer
Is it valid to typecast to a pointer to a variable length array type?
Is it valid to typecast to a pointer to a variable length array type?
int main() {
int n = 10;
int m = 20;
int (*p)[n][m] = malloc(sizeof(int[n][m]));
void *q = p;
int a = n;
int b = m;
(*(int (*)[a][b])q)[5][5] = 1;
…
user3810155
0
votes
0 answers
gcc allocate memory for variant-array
I hace a question about gcc allocate memory for a variant array. If the C code is like below.
long vframe(long idx, long n, long *q) {
long i = 1;
long *p[n];
p[0] = & i;
for (i = 1; i < n; i++) {
p[i]…

marcocr xu
- 1
- 1
0
votes
1 answer
Why can I initialize the size of an array by taking user input in C++?
Given that user input is taken at runtime but array is created during compile time. How and why does this piece of code work?
#include
using namespace std;
int main(){
int n;
cin>>n;
int arr[n]; //Why can I use this statement…
0
votes
1 answer
What is "int (*arr)[cols]" where "cols" is a variable, in C++?
I am reading this to consider about how to dynamically allocate memory for a two-dimensional array.
I notice that a variable value cols can be used as size to define int (*arr)[cols], as C language has variable-length arrays(VLA) feature, then I try…

rustyhu
- 1,912
- 19
- 28
0
votes
1 answer
How are variable length arrays implemented at the machine code level?
This is the question:
How are variable length arrays implemented at machine code (or assembly code - I don't literally want to see some binary code) level? Since many local variables are stored in the .data segment, I guess something different must…

FreelanceConsultant
- 13,167
- 27
- 115
- 225
0
votes
1 answer
passing argument 1 of 'better' makes pointer from integer without a cast
Here's a fairly simple program that finds the max element of an 2d array grades and prints it out to the screen
#include
const int t = 5;
int num_of_students;
int better(int grades[num_of_students][t], int num_of_students)
{
int i, k;…

pavlosdais
- 1
- 2
0
votes
3 answers
Can anyone tell how can I get this done: code of relation of array with pointers
#include
int main(void){
const int size=5;
int grades[size]={34,23,67,89,68};
double sum=0.0;
double *ptr_to_sum=∑
int i;
printf("\n my grades are:\n");
for(i=0;i

Sparkle
- 9
- 1
- 2
0
votes
1 answer
While i use two cin input to enter a data into the array the first input is working fine but the second array input are getting arbitrary values
I am trying to take two input and save it to two different arrays but the first array is input is getting stored perfectly but the second input value is arbitrary I don't get why is it happing
#include
using namespace std;
int main()
{
…

Raj Gupta
- 3
- 4
0
votes
2 answers
I am getting an error in my declaration stated "variably modified 'queue' at file scope"?
Here is a segment of code. What should I do to make queue global and to take its max size from the user?
#include
int max;
int queue[max];
int main()
{
scanf("%d",&max);
return 0;
}
0
votes
1 answer
What's the best way to fill multiDimensional Array
I am trying to find the best way to fill 2D Array with a specific value.
Is there any better way to loop the 2D Array?
I tried memset doesn't work I tried std::fill but I doubt there is something wrong with my code.
void fillMultipleArray(int m, int…

ymyh
- 11
- 6
0
votes
1 answer
Is there a way I can initialize a VLA within a function in Microsoft Visual Studio 2019 (C++)?
I am essentially trying to write a function that acts as np.reshape, but in C++. I want to take an input matrix, define the dimensions of the output matrix, and have the code create an output array of the appropriate size. I am working in Microsoft…

Andrew Klein
- 1
- 1
0
votes
5 answers
ERROR C2371 Override, the default format is different. what is the error point?
#include
int main(void) {
int list_size;
printf("size of the array:");
scanf("%d", &list_size);
int list[5];
for (int i = 0; i < list_size; i++) {
scanf("%d", &list[i]);
}
printArray(list, 5);
…

아이스초코바닐라
- 11
- 2
0
votes
4 answers
Returning the last digit of every number in an array
My problem is that I'm trying to return the last digit of every element in an int array but the function below rather returns the last element of the array. How would I go about doing this.
Array: {10, 12, 41, 23, 71}
Expected output: 0, 2, 1, 3,…

vorcorur
- 13
- 2
0
votes
0 answers
Reading Array Lengths and Calculating Discounts in C
I have a program in C to stdin products and according prices, and the program calculates and applies user input discount to all of the standard prices, however, I have 2 problems with my codebelow:
```
int ReadArray(float arr[])
{
int size = sizeof…

soundsfierce
- 45
- 2
- 9
0
votes
2 answers
C error: variable-sized object may not be initialized
I'm currently learning C language from youtube and this is one of the code about the 2D arrays:
#include
int main()
{
int const columns = 3;
int const rows = 2;
int grades[rows][columns] = {
{12, 23, 45},
{64,…

Camille
- 1
- 1