83.5k views
5 votes
The programmer must initialize variables when they are declared

1 Answer

7 votes

Answer: When you declare a variable, you should also initialize it. Two types of variable initialization exist: explicit and implicit. Variables are explicitly initialized if they are assigned a value in the declaration statement. Implicit initialization occurs when variables are assigned a value during processing.

Step-by-step explanation:

For example, in JavaScript

var PaintAmount = 50; -declare and initialize

function setup() {

creatCanvas(200, 200);

}

function draw() {

ellipse(PaintAmount, PaintAmount) -use the variable PaintAmount

}

or rather in Java,

package random;

public class something() {

Public static void Main(String []args) {

string name; // this is declaring the variable with the example type

string name = new string; //this initializes the declared variable

}

}

User Asaf Katz
by
5.6k points