Skip to main content
Filter by
Sorted by
Tagged with
7 votes
3 answers
569 views

This question arose from a remark Eric Postpischil made in another thread. I have a hard time understanding the use of variable length arrays (VLAs) as function parameters: The array size is not ...
Peter - Reinstate Monica's user avatar
1 vote
2 answers
1k views

Given these two constructors: SomeClass(int... params) { // Do things } SomeClass(long... otherParams) { // Do other things } What happens when an object foo is instantiated? SomeClass foo = ...
Anilla's user avatar
  • 151
1 vote
2 answers
407 views

I would like to allocate memory for arrays, when their sizes are not known until run time, in C++. I often use constant (compile-time) allocation; but would like to make progress towards "always" ...
DrTSPC's user avatar
  • 13
0 votes
1 answer
161 views

I'm writing code that deals with data received from the UDP protocol in the application layer. This is the function prototype used to receive data from the UDP protocol: int my_recv_UDP(int s, ...
Andy Lin's user avatar
  • 481
2 votes
2 answers
407 views

I created a C99 VLA function as such : void create_polygon(int n, int faces[][n]); I want to call this function in another function where I would allocate my two-dimensional array : void parse_faces(...
emandret's user avatar
  • 1,449
6 votes
2 answers
479 views

I was reading about dynamic memory allocation and static memory allocation and found the following about dynamic memory allocation: In the programs seen in previous chapters, all memory needs were ...
Vasi Marin's user avatar
0 votes
3 answers
1k views

I have a code; x = np.linspace(0, 12, 200, False, True, None) when I print x, I get; (array([ 0. , 0.06, 0.12, 0.18, 0.24, 0.3 , 0.36, 0.42, 0.48, 0.54, 0.6 , 0.66, 0.72, 0.78,...
JuhBuh's user avatar
  • 9
8 votes
1 answer
428 views

As you may know, VLA's haves pros and cons and they are optional in C11. I suppose that the main reason to make VLA's optional is: "the stack can blow up": int arr[n]; /* where n = 1024 * 1024 * ...
David Ranieri's user avatar
2 votes
5 answers
201 views

File extension: .cpp I have the following code: int main() { int N; cin >> N; int myArray[N]; return 0; } I get an error when I'm trying to run that program if I input N as 1,000,...
Richard's user avatar
  • 7,493
4 votes
1 answer
3k views

I have the following simple source #include <iostream> int main() { int nv; nv = 3; int arr[nv] = { 0, 2, 5 }; return 0; } When compiling with GCC on system 1 I get error: ...
sancho.s ReinstateMonicaCellio's user avatar
13 votes
3 answers
1k views

#include <iostream> using namespace std; int main() { int rows = 10; int cols = 9; int opt[rows][cols] = {0}; for (int i = 0; i < rows; ++i) { for (int j = ...
dev_nut's user avatar
  • 2,552
15 votes
3 answers
2k views

I'm using MinGW to compile for C++11 and I found out that this doesn't throw an error: int S; cin>>S; char array[S]; While this does ("storage size of 'array' isn't known"): char array[]; To ...
Floella's user avatar
  • 1,397
-1 votes
1 answer
157 views

I'm having a problem in running the following code. It is giving me a segmentation fault as a runtime error. #include <iostream> using namespace std; int main() { int n; cout << "...
oshhh's user avatar
  • 151
1 vote
1 answer
74 views

Given the following two declarations, what is the difference? int foo ( int a, int b, int c[a][b] ) { int foo ( int a, int b, int c[][2] ) { I understand the top statement is a "Variable Length Array"...
Evan Carroll's user avatar
-4 votes
2 answers
1k views

I'm currently working on an assignment where I must find a way to output the longest common subsequence of two strings. In all of the other places I have found implementations of this code, they all ...
drewalc's user avatar
  • 17
3 votes
1 answer
395 views

According to GNU's documentation on Arrays of Variable Length, one can use the sizeof operator for determining the size of a variable length array that was passed into a function: You can also use ...
dtracy's user avatar
  • 33
-4 votes
1 answer
72 views

int n;cin>>n; int arr[n]{}; I have a small problem ,why is this decleration of array wrong?I have used it on Codechef several times until recently i got a WA! After this I declared array as, ...
rookieprogrammer's user avatar
1 vote
2 answers
164 views

As noted here, when returning variable-size data from a C function, you either: Pass a pointer and max length. Return a flag indicating if max is reached. Return a pointer to dynamically allocated ...
Taylor's user avatar
  • 6,508
6 votes
2 answers
2k views

In C99, flexible array members (of a structure) and variable length arrays were mandatory parts of the standard — conforming C99 compilers (implementations) have to support them both. In C11, an ...
Jonathan Leffler's user avatar
3 votes
2 answers
453 views

I have an operation as follows to which the driver needs to send an array of qubits. operation myOp(qubits: Qubit[]) : () { // uses elements from the qubit array } How do I find the ...
Mahathi Vempati's user avatar
1 vote
1 answer
783 views

I'm writing a function that needs to test some external SPI flash memory. By accident during development, I used this code void __TO_FLASH__ slcTestCache(uint8_t len) { uint16_t wcrc = 0xFFFF, ...
yo3hcv's user avatar
  • 1,679
0 votes
4 answers
310 views

Here's the code: int EdgeCount = 0; int numOfEdges = 0; void addEdge() { // some code numOfEdges++; } int EdgeWeightArray[numOfEdges]; // error I want that global array with variable ...
umair mughal's user avatar
1 vote
2 answers
104 views

I'm currently studying variable length array and automatic storage. I have the following code that allocate memory for an variable length array myArray inside function vla, and return a pointer to ...
Thor's user avatar
  • 10.1k
0 votes
5 answers
1k views

When we create an array on the stack most compilers will want to know the size of the array which will be determined at compile time so generally we can't get a user to enter the size of the array ...
strikeforcefan2013's user avatar
3 votes
2 answers
496 views

CERT's Secure Coding Standard includes an item (API05-C) which encourages the use of conformant array parameters, which is a recommendation I've implemented in a lot of my code (hidden behind a macro ...
nemequ's user avatar
  • 17.7k
3 votes
1 answer
353 views

I have an exercise where I am supposed to use fixed-size arrays and in/out parameters to do stuff on matrices (add, scanf, print, etc.), but I’d like to do it on arbitrary-length matrices and return ...
galex-713's user avatar
  • 165
0 votes
1 answer
67 views

I volunteer teaching coding to young girls to code and one of the more advanced ones was trying to use a 2D array for her JavaScript project, but was struggling with the concept of multidimensional ...
Allison's user avatar
  • 2,389
0 votes
0 answers
37 views

I'm back again with that C question heh. So I'm trying to get the user to input a whole 2d array (size, values, everything), with VLA arrays (im using the latest compiler). Everything is fine up until ...
Tcranmer's user avatar
0 votes
1 answer
311 views

I was trying to understand the working of sizeof operator and I came across this question. Following is the code from that question #include <stdio.h> int main() { int i = 0; int a[i];...
mightyWOZ's user avatar
  • 8,445
13 votes
4 answers
2k views

According to cppreference: If the type of expression is a variable-length array type, expression is evaluated and the size of the array it evaluates to is calculated at run time. It means: if ...
msc's user avatar
  • 35.1k
0 votes
3 answers
805 views

box = { curBox: 0, boxes: document.getElementsByClassName('box'), size: this.boxes.length, //this one won't work orSize: Object.keys(this.boxes).length, //as well as this one preBox: ...
Star Light's user avatar
0 votes
4 answers
974 views

So simple code like: int n; cin >> n; int s[n], p[2*(n-1)][3]; I have to translate to: int n; cin >> n; vector<int> s(n, 0); vector<vector<int>> p(2 * (n - 1), vector&...
DuckQueen's user avatar
  • 900
3 votes
3 answers
485 views

I'd like to initialize an array based on a calculation, but the compiler gives me an error when I try this (I'm using GCC version 6.3.0): const int SCREEN_WIDTH = 800; const int SCREEN_HEIGHT = 600; ...
dvanaria's user avatar
  • 6,783
3 votes
3 answers
1k views

My function prototype is int** rotate(int **arr, int row, int col, int fl); where arr is the two dimensional array, row and col is the number of row and columns of the 2D array respectively, fl is a ...
SB56's user avatar
  • 27
4 votes
4 answers
3k views

If I write variable length array as a locally, like this: #include <stdio.h> int main() { int i=1; int a[i]; printf("%zu",sizeof(a)); } It working fine in GCC compiler. But, If I ...
msc's user avatar
  • 35.1k
1 vote
0 answers
868 views

Everyone! I am trying to develop a neural network using Keras and TensorFlow, which should be able to take variable length arrays as input and give either some single value (see the toy example below)...
Vitaly's user avatar
  • 23
1 vote
3 answers
933 views

I want to include a variable length two-dimensional array pointer as part of a struct, but the c99 compiler gives me the following error on the Array anArray line: "flexible array member in otherwise ...
Rick N.'s user avatar
  • 51
0 votes
1 answer
306 views

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 ...
sansam's user avatar
  • 57
0 votes
3 answers
98 views

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 ...
user avatar
0 votes
2 answers
2k views

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 ...
Kishor Subedi's user avatar
0 votes
1 answer
54 views

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 ...
user avatar
19 votes
1 answer
3k views

Here's a short C program that prompts the user for a number, creates a variable-length array of ints of that size, and then uses pointer arithmetic to step over the elements that were allocated: #...
templatetypedef's user avatar
2 votes
1 answer
445 views

In my function bodies reduce() and initialize(...) I want to work with the array globalArray as a three-dimensional one, where the dimensions are not known until runtime. How do I cast the ...
NoahR's user avatar
  • 1,497
68 votes
5 answers
7k views

I wrote a C program that accepts integer input from the user, that is used as the size of an integer array, and using that value it declares an array of given size, and I am confirming it by checking ...
Rahul's user avatar
  • 995
0 votes
2 answers
53 views

The following short python script: var1 = '7f0000000000000000000000000000000000000000000000000000000000000002' var2 = '01' output = 'evm --code ' + var1 + var1 + var2 + ' run' print(output) Is ...
smatthewenglish's user avatar
1 vote
1 answer
74 views

As C++ primer said, we can't use variable as the dimension of builtin array, so the following code did not work int length = 3; int array[length] = {0, 1, 2}; the error is error: variable-sized ...
danche's user avatar
  • 1,815
-2 votes
2 answers
80 views

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 ...
coder666's user avatar
1 vote
3 answers
137 views

I recently discovered that this kind of declaration works with my C++ compiler int h, w; cin>>h>>w; int a[h + 1][w + 1], f[h + 1][w + 1]; Should I use this type of declaration to ...
Van Manh's user avatar
  • 149
4 votes
2 answers
252 views

Why does this work? #include <iostream> int main() { std::cout << "Enter a number: "; int arraySize; std::cin >> arraySize; int ...
Alex's user avatar
  • 63
1 vote
2 answers
2k views

I'm creating a navigation bar in AngularJS. I am showing and hiding the submenu 'div.farm-links' on mouseover and mouseleave respectively on 'div.menu-links'. Now, in my submenu whenever 'child....
Sunny's user avatar
  • 922

1
3 4
5
6 7
9