initialization Questions

10

Solved

If I don't assign a value to a variable when I declare it, does it default to zero or just whatever was previously in the memory? e.g. float x;
Woodrowwoodruff asked 17/5, 2011 at 14:48

10

Solved

What is the proper way to initialize a null variable in .NET? I've been told by one of my colleagues that hard defining of a variable to null is a slowdown. int var1; // good practice string s1; /...
Falls asked 28/8, 2010 at 20:16

16

Was there any reason why the designers of Java felt that local variables should not be given a default value? Seriously, if instance variables can be given a default value, then why can't we do the...
Disloyalty asked 6/1, 2009 at 7:3

5

Solved

From "C++ Primer" by Lippman, When we define a variable, we should give it an initial value unless we are certain that the initial value will be overwritten before the variable is used f...
Astor asked 2/1, 2022 at 17:25

7

Solved

What's meant by parameter (int initialCapacity) in an ArrayList, I thought it's the number of elements but it didn't work when I did this: public class MyClass { private ArrayList<Integer> ...
Kata asked 13/11, 2010 at 12:24

4

Solved

Let us consider the following classes struct test1 { int a; int b; test1() : a(0), b(0) {} }; struct test2 { int a; int b; test2() { a = 0; b = 0; } }; Now, I know that test1() constructor ...

7

Solved

class superClass {} class subClass extends superClass{} public class test { public static void main() { superClass sc1 = new subClass(); subClass sc2 = new subClass(); //whats the differen...
Wiskind asked 24/3, 2013 at 7:34

5

i have a defined a function with a parameter in javascript, and i don't know how to initialize it's parameter, any one help me. the code is bellow <br/>Enter a number: <input type="text" ...
Burgomaster asked 7/6, 2015 at 10:31

2

Solved

In studying for the Java certification test I learned that static initialization blocks run once when the class is loaded, in order of appearance within the source code, that instance initializatio...
Supplejack asked 16/12, 2013 at 20:9

17

Solved

Is it possible to initialize structs in C++ as indicated below: struct address { int street_no; char *street_name; char *city; char *prov; char *postal_code; }; address temp_address = {...
Civilian asked 17/7, 2012 at 5:46

5

Solved

I'm studying for the final exam for my introduction to C++ class. Our professor gave us this problem for practice: Explain why the code produces the following output: 120 200 16 0 using namespace...

5

Is there a way to automatically bind to self (some of) the arguments of the __init__ method? For example, suppose we have: class Person: def __init__(self, name, age, address): self.name = name ...
Imprest asked 19/2, 2011 at 1:49

4

Solved

I'm working through a learn-swift playground and upgrading it to Swift 2.0 as I learn the language. The following code (which likely worked with prior versions of Swift) now generates two errors: "...
Andie asked 26/12, 2015 at 19:33

6

C# delegates have always been difficult for me to grasp and so I was very happy to stumble across logicchild's article on The Code Project web site titled "C# Delegates: Step by Step". He has a ver...
Denysedenzil asked 20/9, 2010 at 11:9

2

Solved

This code is taken from IncludeOS github page. I modified it a bit so that it compiles without other header files. find function from IncludeOS is a bit too verbose, so I want to simplify it. But a...
Kozloski asked 25/11, 2017 at 13:56

11

Solved

struct x { char a[10]; char b[20]; int i; char *c; char *d[10]; }; I am filling this struct and then using the values. On the next iteration, I want to reset all the fields to 0 or null befo...
Sulphurize asked 31/7, 2011 at 19:20

1

Solved

In the next program, struct B with deleted copy-constructor is thrown and caught by value: struct B { B() = default; B(const B&) = delete; }; int main() { try { throw B{}; } catch( B ) {...

6

Solved

The initialization process of a group of classes that share a common parent can be divided into three parts: Common initialization Subclass-specific initialization Common post-initialization Cu...
Belew asked 27/4, 2009 at 20:38

1

Typically, we can create an array using brace initialization of dynamic allocation by int* arr = new int[5]{1,1,2,4,5}; But would this be possible using smart pointers, specifically using std::mak...
Eximious asked 15/10, 2021 at 7:9

8

Solved

I want one long list, say [1,2,3,4,5,15,16,17,18,19] as an example. To initialize this, I try typing: new_list = [range(1,6),range(15,20)] However this doesn't do what I want, returning: [[1, 2...
Mauer asked 19/12, 2012 at 19:15

4

Solved

I read through the main answers on usage of slots and it has given me an idea of how and where to use __slots__ . Now, I am porting a code from Python 2 to Python 3 which is similar to as followi...
Mephistopheles asked 27/1, 2017 at 11:46

5

Solved

MyClass a1 {a}; // clearer and less error-prone than the other three MyClass a2 = {a}; MyClass a3 = a; MyClass a4(a); Why?
Duaneduarchy asked 14/8, 2013 at 3:56

3

I have a lazy loaded module that I'm trying to add APP_INITIALIZER but its not firing. I have the exact same syntax as my main app where its working as expected. Does a lazy loaded module fire the ...
Transpacific asked 11/4, 2018 at 20:13

11

Solved

I need just dictionary or associative array string => int. There is type map C++ for this case. But I need only one map forall instances(-> static) and this map can't be changed(-> const); I hav...
Neurotic asked 14/4, 2010 at 9:38

4

Solved

I'm having a look at the code at this page: http://golang.org/pkg/net/http/ And there's one thing I don't understand - at some point, a new structure is created and initialized like this: client...
Emelinaemeline asked 2/2, 2013 at 16:11

© 2022 - 2024 — McMap. All rights reserved.