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
0
votes
1 answer

Declaring a variable of user-defined type for later initialization

I want to create a global variable called process without assigning anything to it in a first moment. Later on I'll spawn a new process in the operating system, and assign it to that variable. It can be done in C# like so: class TestCS { …
Marc.2377
  • 7,807
  • 7
  • 51
  • 95
0
votes
3 answers

GUI - JFrame: declaring variables

In the following code I have created 3 variables: public class tuna extends JFrame { //Creating 3 text fields private JTextField item1; private JTextField item2; private JTextField item3; what I dont understand is why I then need…
user2971033
0
votes
1 answer

variable may not have been initialized

inside of the arrayAverage method, avg has the right value (I tested it by puting println (avg) inside of the method. When i call the method from my main method and then print avg, netbeans tells me that the variable may not have been initialized. …
user2809114
  • 97
  • 4
  • 15
0
votes
1 answer

Variable might not have been initialized in an if/else if statement

I have already posted this code, however there's more problems, this time with a variable initialization error. The error shows up on line 68 with the variable playerMove. I have scoured the internet on as to why the it complains that the variable…
Showman
  • 55
  • 2
  • 6
0
votes
2 answers

variable initialization with int()

I was trying some different ways of initializing variables. int a(0); cout<
lukai
  • 536
  • 1
  • 5
  • 20
-1
votes
4 answers

Where to initialise a variable in zend application which i will need in my whole application?

I want to initialise a variable which i need to use across my zend application. Where am i supposed to initialise it ? In index.php or in bootstrap.php ?
-2
votes
1 answer

Different results when initializing a variable inside and outside for loop

I have tried a backtracking algorithm and receive different results when I initialize a variable inside and outside a for loop, but I don't understand why. #include int a[10]; int n; int i; int j; //difference void display(){ for…
-2
votes
3 answers

C variable initialization and execution

In C, we know that without initializing a variable, it holds a garbage value. Yet in online compilers and also, in an IDE, when I tried this program it got compiled and there was a perfect output. When I tried to print the same without the while…
-2
votes
1 answer

Is there a more concise method to initialize these variables?

m is either 0, 1, 2, or 3: if m==0 afit0=afit(1); elseif m==1 afit0=afit(1); afit1=afit(2); elseif m==2 afit0=afit(1); afit1=afit(2); afit2=afit(3); elseif m==3 afit0=afit(1); afit1=afit(2); afit2=afit(3); …
-2
votes
2 answers

Which one gives me better performance in variables declaration?

I need to know which one of the following examples gives me higher performance? Object O = someValue; if (condition){ //statements //statements } else { //statements //statements } Or Object O; if (condition){ O = someValue; …
-2
votes
1 answer

When we initialize the data type char* and when not?

Firstly, look at the following simple code: char str[80] = "This is - my text - for test"; const char s[2] = "-"; char *token; token = strtok(str, s); while (token != NULL) { printf(" %s\n", token); token = strtok(NULL, s); } The…
Lion King
  • 32,851
  • 25
  • 81
  • 143
-2
votes
3 answers

NullPointerException when adding node objects to an ArrayList

I'm getting a NullPointerException when I try to run this code. I've assigned Nodes 2,3,and 4 as children nodes to Node1. I tried to create a method that will go through all the children nodes in Node1 and return the list. I'm not sure what I'm…
-5
votes
2 answers

Multiple ajax calls in jquery

I am using jquery for my project. I have the following requirements: I need to make a function call which invokes 5 other functions. These 5 functions are ajax calls which work independent of each other. The ajax calls get data from server and…
-5
votes
1 answer

GUI - Java Error While Running

I am creating a Address Book and all the code is done but I keep getting an error! this is the error: Exception in thread "main" java.lang.NullPointerException at java.awt.Container.addImpl(Unknown Source) at java.awt.Container.add(Unknown…
1 2 3 4 5 6 7
8