Questions tagged [array-initialize]

11 questions
1157
votes
26 answers

How to initialize all members of an array to the same value?

I have a large array in C (not C++ if that makes a difference). I want to initialize all members of the same value. I could swear I once knew a simple way to do this. I could use memset() in my case, but isn't there a way to do this that is built…
Matt
  • 84,419
  • 25
  • 57
  • 67
83
votes
10 answers

initialize a const array in a class initializer in C++

I have the following class in C++: class a { const int b[2]; // other stuff follows // and here's the constructor a(void); } The question is, how do I initialize b in the initialization list, given that I can't initialize it inside…
Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319
41
votes
3 answers

How to initialize two-dimensional arrays in Fortran

In C you can easily initialize an array using the curly braces syntax, if I remember correctly: int* a = new int[] { 1, 2, 3, 4 }; How can you do the same in Fortran for two-dimensional arrays when you wish to initialize a matrix with specific test…
Fludlu McBorry
  • 413
  • 1
  • 4
  • 4
30
votes
9 answers

How to set array length in c# dynamically

I am still new to C# and I've been struggling with various issues on arrays. I've got an array of metadata objects (name value pairs) and I would like to know how to create only the number of "InputProperty" objects that I truly need. In this loop…
John Adams
  • 4,773
  • 25
  • 91
  • 131
21
votes
6 answers

Array initialization with default constructor

public class Sample { static int count = 0; public int abc; public Sample() { abc = ++Sample.count; } } I want to create an array of above class, and want each element in the array to be initialized by invoking the…
Nawaz
  • 353,942
  • 115
  • 666
  • 851
8
votes
7 answers

How do you initialise a const array of TGUID from Interface type data, in Delphi?

I want to initialise an array like this - Const MyArray : Array[0..0] Of TGUID = (IInterface); But it results in - [DCC Error] Test.pas(10): E2010 Incompatible types: 'TGUID' and 'string' So to see what would happen I tried this - Const MyArray :…
David
  • 287
  • 3
  • 14
8
votes
6 answers

How do you initialize a 2 dimensional array when you do not know the size

I have a two dimensional array that I need to load data into. I know the width of the data (22 values) but I do not know the height (estimated around 4000 records, but variable). I have it declared as follows: float[,] _calibrationSet; …
Keith Sirmons
  • 8,271
  • 15
  • 52
  • 75
4
votes
4 answers

C#: PointF() Array Initializer

I need to hard code an array of points in my C# program. The C-style initializer did not work. PointF[] points = new PointF{ /* what goes here? */ }; How is it done?
Agnel Kurian
  • 57,975
  • 43
  • 146
  • 217
2
votes
5 answers

Set size on char array in Java

I'm developing an Android application. I want to set size to a char array like this: public char[5] language; But it doesn't work. I have to delete number five to make it work. I want to limit to five characters to language variable. How can I do…
VansFannel
  • 45,055
  • 107
  • 359
  • 626
1
vote
1 answer

Ada initializing an array based on user input

I'm coming from Java/C++ to Ada and am having trouble figuring out the small stuff. Is it possible to declare an array and ask the user for the min/max values then initialize it? I don't like having to define constant values for the MIN and MAX…
ravun
  • 1,523
  • 9
  • 27
  • 45
0
votes
1 answer

C# reset an array to its initialized values?

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 comparison to 0 and anything above the existing value will…
Capn Jack
  • 1,201
  • 11
  • 28