Skip to main content
Filter by
Sorted by
Tagged with
4 votes
3 answers
244 views

In the C17's final draft N2176 document, the 7th paragraph of 6.2.4 section says For such an object that does have a variable length array type, its lifetime extends from the declaration of the ...
Cinverse's user avatar
  • 333
1 vote
1 answer
113 views

I'm looking at the C2Y draft n3467 and trying to wrap my heads around something involving functions taking VLAs. It seems there's an undefined behavior that's not mentioned by the standard. That is: ...
DannyNiu's user avatar
  • 1,671
0 votes
2 answers
77 views

When compiling my program, I get the following error: No matching function for call to 'fillWithRandomNum' Candidate function not viable: no known conversion from 'double[10][Globals::MAX_COL]' to '...
ImDarkk's user avatar
  • 257
1 vote
0 answers
77 views

I have a bit of C code for an ARM Cortex-M0 chip, for which I was investigating the disassembly: int func2(unsigned a) { int h[a]; for (unsigned i = 0; i < a; i++) { h[i] = 0; } int ch;...
Mark van der Wilk's user avatar
20 votes
6 answers
2k views

In C, you can do this: int arr[i]; From what I understand, this is called a VLA—variable length array—which is an array whose size is not known at compile time, which in most implementations is ...
דניאל פ.ח.'s user avatar
3 votes
2 answers
104 views

This compiles fine under C99 const int DIM; int main() { int tab[DIM]; } while the following gives the error int tab[DIM]; int main() { } error: variably modified tab at file scope Why? I know ...
axel's user avatar
  • 91
2 votes
1 answer
112 views

Issue: definition of variable length array (VLA) / known constant size seems to be recursive. C11, 6.2.5 Types, 23 (emphases added): A type has known constant size if the type is not incomplete and ...
pmor's user avatar
  • 6,757
5 votes
1 answer
140 views

Is the following code: #include <stdio.h> void case1(int array[][printf("hello ")][printf("world ")]) {} int i = 0; void case2(int array[][i++][i++]) {} int main(void) { ...
KamilCuk's user avatar
  • 146k
1 vote
1 answer
104 views

I am wondering how difficult it would be to add rudimentary support for something like sizeof T[n] (which to my knowledge is an explicit C construct for a variable length array), to be used in a ...
invertedPanda's user avatar
-2 votes
2 answers
123 views

The first array is multiples of 5, second array is multiple of 9. I was able to store the input but the printed array seems wrong as it did not print my supposed numbers. Any kind soul could help and ...
Muhammad Muttaqin's user avatar
4 votes
1 answer
144 views

@Lundin shows how to check if a passed expression is an array at compile-time here: Lvalue conversion of _Generic controlling expression involving array clang warning wrong?: #define IS_ARRAY(T) ...
Madagascar's user avatar
  • 7,440
3 votes
3 answers
170 views

Currently I am assigning a VLA to a pointer as follows struct Foo { int* array; }; int array[size]; struct Foo foo = { .array = array; }; Is it possible to replace this with an "...
GrandeKnight's user avatar
6 votes
2 answers
143 views

Context The standard says (C17, 6.5.3.4 ¶2): The sizeof operator yields the size (in bytes) of its operand, which may be an expression or the parenthesized name of a type. The size is determined from ...
Lover of Structure's user avatar
2 votes
3 answers
512 views

I first started going down this rabbithole after learning that VLAs (variable length arrays) are not compatible with C++. This is due to the fact that an array of variable length would not have a size ...
B-rad's user avatar
  • 55
0 votes
2 answers
127 views

#include<stdio.h> int main(){ int n; printf("Enter the number:"); scanf("%d",&n); int array[n]; for (int i=0;i<=n;i++){ printf("%...
Shuvarthi Dey's user avatar
1 vote
1 answer
455 views

I have a struct that can be used in a fixed-size or unsized way, where the last element is an array of u8 items. We can write the following struct definition: struct MyStructImpl<E: ?Sized> { ...
Bernard's user avatar
  • 5,800
-1 votes
1 answer
82 views

I'm trying to understand how sizeof() works, so I made 2 arrays, and see what is assembled, I've not used -O3 option because I thought the code to be clearer and the code is not deleted by ...
sefiroths's user avatar
  • 1,563
2 votes
3 answers
983 views

I'm trying to implement the following idea: let command = ...; let request = match subcommand { Some(x) => [command, x as u8, (x >> 8) as u8], None => [command], }; request ...
Roman Liutko's user avatar
0 votes
1 answer
256 views

Here I have two data files with model parameters and RMSEs computed for them. I would like to get those RMSEs plotted for each model separately with the model also displayed on it. Please help. Data ...
user86927's user avatar
0 votes
0 answers
113 views

I understood through this post on how to use a variable in format string. write(*,'(1x,f10.5)')(j(i),i=1,nvar) seems to work but the values in 'j' are displayed row-wise. I want them to be displayed ...
user86927's user avatar
30 votes
2 answers
3k views

I know that the restrict qualifier in C specifies that the memory region pointed by two pointers should not overlap. It was my understanding that the Linux (not SUS) prototype for memcpy looks like - ...
tinkerbeast's user avatar
  • 2,107
1 vote
3 answers
131 views

A program to accept an array and diplay it on the console using functions. Program should contain 3 functions including main() function. Next two functions for accepting values to the array, and ...
Amalshanth's user avatar
0 votes
4 answers
128 views

Hello I am new to coding and was just wondering why the below code: #include <stdio.h> int main() { for(int i = 0; 1 ; i++) { char x; char z[1+i]; x=getchar(); if (x == '\n'){ ...
soda2718's user avatar
0 votes
2 answers
179 views

I have a 2D array of strings char* d2Array[valueA][valueB]. This works fine, I am able to fill it with strings and access them. There is an issue when passing it to a function. You need to specify the ...
user avatar
0 votes
1 answer
103 views

#include <iostream> #include <algorithm> #include <bits/stdc++.h> template<typename T, size_t Size> std::istream& operator>>(std::istream& in, T (&arr)[Size]) ...
mayank garg's user avatar
-1 votes
2 answers
332 views

malloc is slow and allocates on the heap. Good for large objects or objects that need to get their lifetime extended beyond the function where they are created. static allocation is on the stack. ...
Lolo's user avatar
  • 4,219
1 vote
2 answers
182 views

I have the following task: Create a 2d array A[M][N], where M and N are inputted by the user as well the elements in each row and column. There must also be two functions: 1)The first one needs to ...
Rostislav Yanev's user avatar
0 votes
2 answers
140 views

I am trying to make a programm that turns a string into binary. int len = strlen(word); int array2[len] = ascii_v(word, len); int ascii_v(string w, int l) { int array1[l]; for (int i = 0, i &...
Ricci2003's user avatar
-2 votes
1 answer
91 views

Say I have a struct struct GRAPH { NODE* nodes[]; } With a dynamic size for nodes[]. I also have struct NODE { char filename[40]; struct NODE* links[]; } I will know how many links and nodes I ...
04Khey's user avatar
  • 3
2 votes
2 answers
394 views

I'm coding a C program that asks the user to input two variables that represent the 2d array sizes and then print the array, I don't know where the problem is! any help? `#include <stdio.h> int ...
Asmaa Magdy's user avatar
3 votes
3 answers
196 views

I am working on a piece of legacy code (no tests). I stumbled upon a section hidden inside several macros. It generates a warning if compiled with GCC's -Wvla. The code in question is equivalent to ...
Grigory Rechistov's user avatar
-1 votes
1 answer
82 views

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 ...
Giorgi's user avatar
  • 13
2 votes
1 answer
89 views

I am reading C The Complete Reference 4th edition by Herbert Schildt. In Chapter 4 - Arrays and Strings, it mentions "One major reason for the addition of variable-length arrays to C99 is to ...
Saad's user avatar
  • 107
0 votes
0 answers
111 views

To preface: I am new to C and still learning the best way to efficiently code in C. I'm trying to create an dynamic array of structs. I have an array within the struct however the values within the ...
Skyttlez's user avatar
0 votes
3 answers
1k views

So would like to create an 2D array of characters for testing purposes. Here is my code. const int rows = 4; const int columns = 6; //char field[rows][columns]; //fill_field(rows,...
tomastrue's user avatar
7 votes
2 answers
159 views

Probably, there is a contradiction is the C standard for VM types used in conditional operator. Assume: int f(void) { return 42; } Now, what is the type of a following expression? 1 ? 0 : (int(*)[f()]...
tstanisl's user avatar
  • 14.3k
-1 votes
2 answers
108 views

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}; ...
Aaban Saad's user avatar
0 votes
1 answer
117 views

Let's say I have: numResults (Int16ul) resultItems[numResults] where the resultItems is constructed like: ID (does not always increase) strLen my_str[strLen] Now I understand, that I have to use ...
Startin Mohanzl's user avatar
0 votes
1 answer
369 views

I want to convert a float vector to a float array in C++ 20. I searched online and found this solution: #include <iostream> #include <algorithm> #include <vector> int main() { ...
Pepis's user avatar
  • 9
1 vote
1 answer
156 views

I'm trying to program up a 2D dynamically allocated array for a map for a small game. Below is my code, I'm unsure why int* array[yCoord] is throwing up the error that it cannot be a variable length ...
tomparko's user avatar
-2 votes
2 answers
81 views

I'm just taking input for two arrays and manipulating the information. When I take input for both arrays it puts the information from the second into both arrays. In the code below I haven even ...
Molly Dempsey's user avatar
-1 votes
2 answers
63 views

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 ...
emcosokic's user avatar
0 votes
2 answers
86 views

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 ...
Karishma Singh's user avatar
1 vote
2 answers
869 views

So I'm working with this struct type with variable length array member, like this: struct Entry; struct Data { int members; size_t entries_size; Entry entries[1]; }; The entries_size ...
fluter's user avatar
  • 14k
0 votes
3 answers
1k views

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 ...
artur anikin's user avatar
1 vote
3 answers
293 views

I just wanna know why does this method to get the fibonacci number not work thanks. #include <iostream> #include <cctype> #include <cmath> using namespace std; int fibonacci() { ...
Big Yong's user avatar
1 vote
3 answers
1k views

I am very new to C but I am having trouble on what seems a very trivial problem. All I am trying to do is create a n sized array, such that at the time of running I don't know its size and can't ...
Harry Spratt's user avatar
0 votes
1 answer
163 views

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 ...
jk.'s user avatar
  • 1
0 votes
1 answer
162 views

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 ...
YoLo22's user avatar
  • 1
1 vote
3 answers
87 views

What is the problem with the following code? C compiler shows me error: Segmentation fault. #include <stdio.h> #include <math.h> int main() { int n = 4; float A[n][n][n][n]; ...
Luka Kaličanin's user avatar

1
2 3 4 5
9