Questions tagged [variable-initialization]

In computer programming, initialization is the assignment of an initial value for a data object or variable.

In computer programming, initialization is the assignment of an initial value for a data object or variable. The manner in which initialization is performed depends on programming language, as well as type, storage class, etc., of an object to be initialized. Programming constructs which perform initialization are typically called initializers and initializer lists. Initialization is distinct from (and preceded by) declaration, although the two can sometimes be conflated in practice. The complement of initialization is finalization, which is primarily used for objects, but not variables.

119 questions
1
vote
3 answers

Does the order of automatic variables creation correspond to the order of declaration?

Given: void foo() { std::vector v1; std::vector v2; } Is it guaranteed that v1 is constructed before v2, or is the order not defined? I can't find the answer in the standard (even though I know it's there somewhere).
Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335
1
vote
2 answers

Is an int in Objective-C automatically initialized to 0?

I am reading a book called "Programming in Objective-C", Sixth Edition, by Stephen G. Kochan. It has the following statement on page 144 which is confusing me: Local variables that are basic C data types have no default initial value, so you must…
1
vote
2 answers

Variable initialization fails to compile with comma-operator

Why does the line indicated ( in main() ) in the following code not compile? #include #include #include template< typename _T > struct Inventory : public std::map< _T, int > { bool getat(int i, _T &t, int &n) { …
slashmais
  • 7,069
  • 9
  • 54
  • 80
1
vote
1 answer

Variable might already have been assigned

The following code has an error: class A { private final String val; public A(){ this.val = null; } public A(String val){ this(); this.val = val; } } the error is "variable val might already have been assigned Is there a…
0
votes
2 answers

C++, memory and arrays. Creating my own hashmap for exercise. Unexpected data left in memory?

So i'm trying to create a pretty specific for my needs hashmap for a small project where i'm trying to learn c++. I have the following code: template class HashMap { public: HashMap(); virtual ~HashMap(); void add(T value); T get(T…
lfxgroove
  • 3,778
  • 2
  • 23
  • 33
0
votes
1 answer

how to interpolate workflow level variable into another workflow level variable github actions

I'm new to github actions. Below is my workflow: name: Example on: [push, workflow_dispatch] env: APPNAME: 'myapp1' APPURL: "https://mybank/$APPNAME/widgets/hello.json" jobs: test: runs-on: windows-latest steps: - name:…
0
votes
2 answers

Variable initialization in Javascript

There is something that I couldn't understand. I have the following code, which its purpose is to get the total of the two arrays. let r1; let r2; let total; function totalSum(arr_1, arr_2) { for (let i = 0; i < arr_1.length; i++) r1 +=…
0
votes
0 answers

Concept issues about initializing avariable in C++ class

I'm translating a script form matlab to C++ and I'm given a code snipet in c++ so I can fill it. My BIG issue is that my knowledge about C++ is almost nothing, I know how classes work in a basic way so now I'm stuck in a variable initialization…
mikel lasa
  • 23
  • 5
0
votes
1 answer

Is there a way in Java to make labels move without user influence?

I am trying to develop an application where the user moves a can back and forth on the bottom of the screen to try to catch bees as they fall. I have successfullly gotten the can movement working, but I am stuck on the bees' movement. In my current…
jajuub
  • 3
  • 1
0
votes
1 answer

sending a SOAP request with c#

I'm trying to send a SOAP request to a 3rd party web service. I've successfully send and received data from other interfaces in the same service, but I'm having problems with this particular one:
Magic Lava
  • 59
  • 2
  • 8
0
votes
1 answer

Why does initialising the variable outside the event handler and then reassigning it only allow the code to work once?

I'm making a BMI calculator and it works only one time. Which I don't understand. I initialised 2 let variables outside the click event handler just to get the input elements. When I wanted to convert the variables' values using the 'Number()' it…
0
votes
1 answer

Detect and prevent processing of sequential duplicate Tradingview webhook json

I am not very well acquainted with python, but have by much trial and error, and building upon the work of others, developed a simple working and reliable interface between Tradingview (TV) and Interactive Brokers (IB). I have situation where…
0
votes
2 answers

Why can't a global variable be initialised from another global?

int a = 5; int b = a; //error, a is not a constant expression int main(void) { static int c = a; //error, a is not a constant expression int d = a; //okay, a don't have to be a constant expression return 0; } I don't understand what…
0
votes
2 answers

Is there a reason to use zero-initialization instead of simply not defining a variable when it is going to be updated before the value is used anyway?

I came across a code example learncpp.com where they zero-initialized a variable, then defined it with std::cin: #include // for std::cout and std::cin int main() { std::cout << "Enter a number: "; // ask user for a number int…
0
votes
2 answers

JavaScript: Is it possible to declare a variable using another variable's value?

Here is an example of what I'm trying to accomplish: const a = 'name'; const ${a} = 1; The second variable should be: const name = 1; Is this possible? Thank you in advance.