A need to initialize variables

Asked By 0 points N/A Posted on -
qa-featured

In computer science, do variables need to be initialized? What is an Automatic variable and in what instance is this variable applicable.

SHARE
Best Answer by Alex rachel
Best Answer
Best Answer
Answered By 0 points N/A #158995

A need to initialize variables

qa-featured

Hi Shannon,

The matter of defining variables depends on the programming language you are using to write your program.

In C language for instance you must initialize variables before using them, but Java on the other hand doesn't require such initialization of local variables.

So first you need to know what programming language you are using then you can know if you have to initialize your variables or not.

Answered By 0 points N/A #158996

A need to initialize variables

qa-featured

Hi Shannon Stainbrook,

 

In C language, Variables must be initialized before using them. But in JAVA language, Variables need not be initialized before using them. Automatic variables are variables that are declared within the scope of a block, usually a function. These variables are usually allocated from the stack frame. I hope you understand it.

best regards 

Answered By 560795 points N/A #158997

A need to initialize variables

qa-featured

Of course, in order for a variable to be used it needs to be initialized first or in other words you need to declare it first before using it. An automatic variable in computer programming is the kind of variable that can automatically be allocated and deallocated when the program flow starts and set asides the context of the variable.

It mainly applies to lexically-scoped variables where the lexical context is also the context especially the block or function in which the variable is defined. The term “local variable” is normally the same as with automatic variable. Nearly all local variables are automatic local variables though static local variables also exist particularly in C language.

In a static local variable, the allocation or distribution is static and not automatic meaning the variable will only exist while the program is running. In C and C++, all variables that are declared inside a block of code are automatic by default. But it can also be made specific using the auto keyword.

Login/Register to Answer

Related Questions