Skip to main content
Stack Overflow for Teams is now Stack Internal: See how we’re powering the human intelligence layer of enterprise AI. Read more >
Filter by
Sorted by
Tagged with
1 vote
2 answers
173 views

I have a small table of structs, that I would like to refer in code by a short name. However, using a string as name would mean to have some lookup search every time this table needs to be accessed. ...
dronus's user avatar
  • 11.4k
-2 votes
1 answer
164 views

Let Foo be a structure holding an integer. Now, I need to initialize at compilation time an array of Foo from the values coming from an array of integers. Of course, one can hand-write it but having a ...
abcdefg's user avatar
  • 4,315
0 votes
1 answer
125 views

The difference is in 4th line for both code(given below). In 1st one, I declared some variable and then initialized the array. In 2nd one, I initialized the array first and then declared the variables....
Rahul Das's user avatar
0 votes
0 answers
72 views

I'm just a beginner in C++. In my textbook it is stated that, "if the number of initial values is less than the size of the array, they will be stored in the elements starting from the first ...
Aghila C C's user avatar
0 votes
2 answers
214 views

I need to put the output of arr in global array because I need to use the array in main function. How can I initialize the array in global and I don't know the size of it ? any idea please? globarr[]; ...
lena's user avatar
  • 727
0 votes
3 answers
850 views

Why does initializing the array arr work when it is done as a list comprehension (I think that is what the following example is --not sure), but not when each array location is initialized ...
jrive's user avatar
  • 248
55 votes
4 answers
13k views

#include <stdio.h> int main() { char a = 5; char b[2] = "hi"; // No explicit room for `\0`. char c = 6; return 0; } Whenever we write a string, enclosed in double ...
Dan's user avatar
  • 3,068
0 votes
1 answer
121 views

What could be wrong with: let myArray = [UInt](count: 256, repeatedValue: 0) that leads to the error Extra argument 'repeatedValue' in call? I found this in existing code I'm adding to my Swift 5 app....
meaning-matters's user avatar
0 votes
1 answer
116 views

Like with initialization: We take like: Dim a() as integer = {1,2,4,6} And if i want to print the array list it will be 1 , 2 ,4,6 as output But how can i take any value i.e n value to print n ...
Otaku Æriæn's user avatar
0 votes
0 answers
51 views

Basically I'm trying to modify an element in a 2D array. How the array is initialized seems to be effecting the behaviour. I'm new to Ruby so I'm not sure how initializing an array would effect this. ...
Yahoochrom3's user avatar
2 votes
1 answer
101 views

int main() { char a[] = "123454321"; } "123454321" is a string literal and a string literal sets aside memory storage. a is defined by the statement which also causes memory ...
op ol's user avatar
  • 777
0 votes
2 answers
57 views

I want to implement a graph with an array of List<int>, but when I try to initialize the entries with Array.Initialize() with the default values (by calling a parameterless constructor of List&...
Kristiyan Garchev's user avatar
0 votes
2 answers
157 views

I want to initialize a value of all array members to their index. int main() { int i; int arr[10]; for (i = 0; i <= 9; i++) arr[i] = i; } Should I consider the sequence point ...
op ol's user avatar
  • 777
2 votes
2 answers
2k views

I need to initialize a h x h matrix in C with spaces. How to properly do it without cycles? int h = 8; char arr[h][h] = {{' '}}; // does not work....
serge's user avatar
  • 15.4k
0 votes
2 answers
107 views

I wonder If there's a way to assign a dynamic array (C style), values like in the case of a non dynamic array (instead of matrix[0][0] = ...), e.g.: int n = 3; int ** matrix = new int*[n]; for(int i =...
Romero Azzalini's user avatar
2 votes
3 answers
3k views

I'm new to programming and very new to C++, and I recently came across strings. Why do we need a null terminator at the end of a character list? I've read answers like since we might not use all the ...
NewbieToCoding's user avatar
2 votes
2 answers
69 views

I am new to programming. While learning the data structure Array, I came to know that we have to initialize the array with the size, while creating one. But I also saw a code snippet in one of the ...
Saranya's user avatar
  • 79
0 votes
0 answers
45 views

I recall that in C# a notation similar to the one below would be a correct array initializer. int[] array = new int[3] { [1] = 5; }; This should initialize the array with all values as default (0 ...
prenone's user avatar
  • 334
0 votes
2 answers
332 views

I'm trying to do some calculations and get the groups and departments array from there. but if I'm returning it like this [], [] It is giving error, while if I return it like [[],[]] it is working ...
shailjakant's user avatar
4 votes
3 answers
163 views

I have an issue in that I cannot use a certain constructor with an array initializer when using VS2017 (C++14, C++17 and ISO latest). I get an C2397 conversion from 'double' to 'unsigned int' ...
lfgtm's user avatar
  • 1,047
1 vote
1 answer
87 views

I have the following code; char[] leadingDot = { '.' }; string trimStart = fileName.TrimStart(leadingDot); I cannot seem to figure out the syntax to combine it into a single line. ReSharper has no ...
CarComp's user avatar
  • 2,056
4 votes
2 answers
297 views

I will be reading data from a byte stream. Are the indices given by Kotlin to an array generation function (as described in https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/-init-.html) ...
QED's user avatar
  • 9,953
1 vote
1 answer
3k views

I'm wondering if there is a proper way to do this. Given the example: struct Test { static std::array<unsigned, 123> data; }; std::array<unsigned, 123> Test::data = {}; If I want to ...
Hex Crown's user avatar
  • 763
4 votes
2 answers
560 views

I tried the following code: int a[4] = {0}; int b[4] = {5}; int c[4]; printf("%d %d %d %d %d %d\n", a[0], a[3] , b[0], b[3], c[0], c[3]); And got the following result: 0 0 5 0 random random While I ...
Stoogy's user avatar
  • 1,351
1 vote
3 answers
510 views

All of the reading I've done says that passing a non null-terminated char array to std::strlen is undefined behavior and will likely cause the program to crash. However, the code below (compiled with ...
brianxk's user avatar
  • 63
4 votes
1 answer
495 views

According to this thread, initializing an array with a shorter string literal pads the array with zeros. So, is there any reason why these two functions (test1 and test2) would produce different ...
Lou's user avatar
  • 4,514
3 votes
2 answers
4k views

I am viewing the assembly output of this function: extern void write(char * buff); void test(int x) { // copy "EXAMPLE\0\0\0\0\0..." char buff[16] = "EXAMPLE"; // set ...
Lou's user avatar
  • 4,514
3 votes
2 answers
141 views

I am following the book "C Primer Plus" and encounter such a snippet of code: // designate.c -- use designated initializers #include <stdio.h> #define MONTHS 12 int main(void) { int days[...
Wizard's user avatar
  • 22.7k
9 votes
1 answer
703 views

I have the following code snippet: int i[] = {42, i[0]}; Is such initialization allowed or leads to undefined behaviour? Three major compilers (gcc, clang, msvc) give me 42 for i[1]. Hence looks ...
αλεχολυτ's user avatar
1 vote
1 answer
1k views

I'm trying to use a C-style array as a map through enums but I can't initialize arrays by parts... I'll explain myself better through code: I have something like: enum Objects{CAR = 0, PLANE, BOY}; ...
BetaCoder's user avatar
1 vote
0 answers
49 views

Consider the following function which takes a reference to an array of a size N deduced at compile time: template <size_t N> void array_consumer(unsigned const (&source)[N]) { // ... } I ...
BeeOnRope's user avatar
  • 66.3k
1 vote
0 answers
62 views

So I've found this code works: int foo[] = {0, foo[0] + 1, foo[1] + 2, foo[2] + 4 }; Is this officially legal? I thought that I was making an initializer_list here, but if I can access previously ...
Jonathan Mee's user avatar
  • 39.1k
-2 votes
3 answers
4k views

What is the language grammatical problem in my code? I want to declare an array of queues. Is this the right way to declare and use them? public static void Main(string[] args) { ...
deepsigner's user avatar
2 votes
3 answers
469 views

I am aware of C's (pretty neat) array initialization syntax, like char arr[12] = {[0] = '\n', [4] = 'z'}; to initialize some specific members in the array, but is there a means to initialize a whole ...
joH1's user avatar
  • 602
6 votes
2 answers
214 views

I want to initialise all members of the array to zero, or nullptr struct Window{ int a;}; int main() { Window* list[4] = { 0, 0, 0, 0 }; Window* list2[4] = {0}; Window* list3[4] = {}; ...
Zebrafish's user avatar
  • 16.3k
2 votes
3 answers
1k views

I would like to do this with a macro: typedef struct _TIMER_llist { struct _TIMER_llist *next; uint32_t time; const int id; } TIMER_llist; TIMER_llist _timer_llists[] = { { .id = 1, ....
engelant's user avatar
  • 143
0 votes
1 answer
449 views

※ This question is a continuation of below problem How to use nested loop for a Matrix cell in excel vba I would like to pass dynamic Array(arguments), and i was trying below, but it is not working ...
DIO's user avatar
  • 15
0 votes
2 answers
834 views

I am trying to add some polynomials after multiplying each by a different constant. I have been able to setup the arrays and multiply by the constants, but when I get to the addition of each position ...
jovany merham's user avatar
1 vote
4 answers
1k views

Why are my array of static bools not initialized properly? Only the first one is initialized - I suspect this is because the array is static. The following MWE was compiled with GCC and is based on a ...
user3235290's user avatar
0 votes
1 answer
3k views

Lets say I have an array of employee wages in the order of average, max, and min: int[] wages = {0, 0, Int32.MaxValue}; The above code is initalized so that as Im finding the max I can do a ...
Capn Jack's user avatar
  • 1,251
3 votes
3 answers
2k views

I'd like to use an array initializer to build one byte array out of another byte array as well as some other bytes that form a header/trailer. Basically, I'd like to do something like this: byte[] ...
8bitcartridge's user avatar
-1 votes
1 answer
1k views

I want to initialize multidimensional array in C. I use usually the code below. #include <stdio.h> int main() { int a[10][10] = {{0}, {0}}; return 0; } Is my code right, and is there ...
J. H. Kim's user avatar
20 votes
2 answers
942 views

We are transitioning C code into C++. I noticed that the following code is well defined in C, int main(){ //length is valid. '\0' is ignored char str[3]="abc"; } as it is stated in Array ...
Trevor Hickey's user avatar
1 vote
4 answers
1k views

So this is my program so far: #include <iostream> #include <windows.h> using namespace std; int colonne; int ligne; void initDamier (int damier[ligne][colonne]) { for (int i = 0; i &...
D Sam's user avatar
  • 77
-3 votes
1 answer
1k views

How can I set the vars array to all zero '0' values? typedef char array_t[100]; void setvars(array_t vars[], int lens[]) { /*vars : 10 numbers lens : the length of 10 numbers in vars */ . . . } ...
Chanchan's user avatar
0 votes
1 answer
220 views

I'm a programming newbie and I just started learning about arrays. What confuses me is the way one can initialize a multidimensional array in C#. And that is because I don't specify the coordinates of ...
user avatar
0 votes
2 answers
108 views

So I want to get the position of each of the element within the array initialiser for example: int [][][] testArray = new int [][][] {{{1,2},{3,4}},{{5,6},{7,8}}}; how would i be able to get the ...
Alan Liang's user avatar
2 votes
1 answer
599 views

This following code does not compile: int main() { int a[][] = { { 0, 1 }, { 2, 3 } }; } The error message produced is error: declaration of 'a' as multidimensional array must have ...
Lingxi's user avatar
  • 15.1k
-1 votes
2 answers
72 views

I have some classes nested one in another public abstract class I { public abstract int f(); } public class J { private List<I> li; public J(List<I> l) { li = l; ...
haael's user avatar
  • 1,059
0 votes
0 answers
37 views

Consider the following hierarchy of classes: struct B { int i; }; struct D : B { int j; }; B is aggregate class, but D is not (because of base class existance). Is there a way to initialize ...
αλεχολυτ's user avatar