array-initialization Questions
20
Solved
What are all the array initialization syntaxes that are possible with C#?
Cyclopean asked 15/4, 2011 at 14:27
9
Solved
Hello i'm learning C++11, I'm wondering how to make a constexpr 0 to n array, for example:
n = 5;
int array[] = {0 ... n};
so array may be {0, 1, 2, 3, 4, 5}
Carminecarmita asked 26/9, 2013 at 4:13
2
Solved
I need to initialize each element of an array to a non-constant expression. Can I do that without having to first initialize each element of the array to some meaningless expression? Here's an exam...
Mathematician asked 3/10, 2014 at 19:36
4
Solved
By default, an array of reference types gets initialised with all references as null.
Is there any kind of syntax trick to initialise them with new default objects instead?
eg
public class Chil...
Colicweed asked 19/9, 2012 at 9:56
4
Solved
#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 quotes, C ...
Blende asked 13/9, 2021 at 12:18
7
Solved
I'm new to Scala ,just started learning it today.I would like to know how to initialize an array in Scala.
Example Java code
String[] arr = { "Hello", "World" };
What is the equivalent of the a...
Foin asked 7/10, 2010 at 11:8
8
Solved
I've been using C++ for a few years, and today I saw some code, but how can this be perfectly legal?
int main(int argc, char **argv)
{
size_t size;
cin >> size;
int array[size];
fo...
Mountain asked 10/4, 2009 at 10:21
5
Solved
I want to fill up a dynamic array with the same integer value as fast as possible using Powershell.
The Measure-Command shows that it takes 7 seconds on my system to fill it up.
My current code (sn...
Discrown asked 26/7, 2013 at 7:52
1
Solved
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]. Henc...
Pitarys asked 13/8, 2018 at 9:5
2
Solved
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] = {};
Window...
Messroom asked 20/12, 2017 at 1:5
6
Solved
I've got a method that receives a variable int. That variable constitutes an array size (please, don't offer me a vector). Thus, I need to init a const int inside my method to initialize an array o...
Yean asked 22/1, 2013 at 13:5
5
Solved
I just looked at this SO Post:
However, the Columbia professor's notes does it the way below. See page 9.
Foo foos = new Foo[12] ;
Which way is correct? They seem to say different things.
Part...
Cowberry asked 5/10, 2013 at 13:10
3
Solved
Take the following example:
private int[] list;
public Listing() {
// Why can't I do this?
list = {4, 5, 6, 7, 8};
// I have to do this:
int[] contents = {4, 5, 6, 7, 8};
list = contents;
}...
Leticia asked 28/11, 2011 at 20:54
6
Solved
By accident I found that the line char s[] = {"Hello World"}; is properly compiled and seems to be treated the same as char s[] = "Hello World";. Isn't the first ({"Hello World"}) an array containi...
Forwardness asked 13/4, 2012 at 19:39
2
Solved
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 ini...
Barnhill asked 16/6, 2016 at 14:6
3
I have the following:
typedef struct
{
uint8_t BlockID;
uint32_t Copies;
uint16_t Size;
}NVMM_ConfigType;
const NVMM_ConfigType NvmmCnf_Layout[6] =
{
{ 1, 1, 4},
{ 2, 3, 4},
{ 5, 5, 16},
{...
Controvert asked 30/7, 2015 at 14:43
4
The following code makes me confused:
Object[] arr1 = new String[]{"a", "b", "c"};
Object[] arr2 = {"a", "b", "c"};
String[] a = (String[]) arr1; // ok
String[] b = (String[]) arr2; // ClassCastE...
Leralerch asked 29/7, 2015 at 12:41
4
Solved
Consider the following code in which we initialize part of D based on another part of D:
struct c {
c() : D{rand(), D[0]} {}
int D[2];
};
int main() {
c C;
assert(C.D[0] == C.D[1]);
}
Is th...
Laaland asked 27/6, 2015 at 17:48
1
I have a class Thing sporting no default constructor.
Now we define another class, which now has to initalise the array elements at once, as without a default constructor, no late assignment can ...
Pairs asked 20/4, 2015 at 9:16
3
Solved
I have a class with an array member that I would like to initialize to all zeros.
class X
{
private:
int m_array[10];
};
For a local variable, there is a straightforward way to zero-initialize (s...
Homecoming asked 9/12, 2014 at 15:1
12
Solved
string[][] Tablero = new string[3][3];
I need to have a 3x3 array arrangement to save information to. How do I declare this in C#?
Bernita asked 28/9, 2010 at 15:5
2
Solved
Array initialization can be done with or without the ':
int a[8] = '{0,1,2,3,4,5,6,7}; // Packed
int b[8] = {0,1,2,3,4,5,6,7}; // Unpacked
Is there a correct way, assuming the array uses an un-p...
Sunbreak asked 18/4, 2014 at 21:59
3
Solved
On initializing a Variable length array compiler gives an error message:
[Error] variable-sized object may not be initialized
Code snippet:
int n;
printf("Enter size of magic square: "...
Biosphere asked 26/6, 2013 at 23:54
1
Solved
I like c++11 variadic templates, so I often write some little codes with it.
See this example:
#include <cstdio>
#include <type_traits>
#include <vector>
template< typename ...
Aaronaaronic asked 25/11, 2013 at 6:28
4
Solved
How do I smartly initialize an Array with two (or more) other arrays in C#?
double[] d1 = new double[5];
double[] d2 = new double[3];
double[] dTotal = new double[8]; // I need this to be {d1 the...
Fireplace asked 7/5, 2010 at 12:54
1 Next >
© 2022 - 2024 — McMap. All rights reserved.