Skip to main content

Define variable and initialization of a variable ? Why is it important ?


Answer:

Variable:
A variable is a data name that may be used to store a data value; unlike constants they can change their value during program execution a variable may take different values at different times during execution.





General form for declaring a variable:
            data_type name_of_the_variable;
Example:
            int sub1,sub2;
            float sum;

Initialization:
when a variable is assigned a value at the declaration time, then it is called initialization.

General form:
            data_type variable_name=constant;

Example:
            int final_value=100;
            char yes=’x’;
            double balance=75.83;

Importance of Initialization:
Ø  It is important to use an initialization, because it provides the user some advantages than a separate assignment statement.
Ø  Global and static local variables are initialized only at the start of the program. Local variables are initialized each time the block, in which they are declared, is entered. Un-initialized global and static local variables are automatically set to zero.
Ø  By using this, compiler may be able to produce faster code.

Ø  Also, this saves some typing effort on user’s part.

Popular posts from this blog

Draw the basic organization of computer

Answer:                 The basic organization of computer__ Input Unit: ·          It accepts (or reads) instructions and data from outside. ·          It converts these instructions and data in computer acceptable form ·          It supplies the converted instructions and data to the computer system for further processing. Central Processing Unit (CPU): Control Unit: Control unit of a computer system manages and coordinates the operations of all other components of the computer system. Arithmetic Logic Unit(ALU): Arithmetic logic unit of a computer system is the place, where the actual executions of instruction, takes place during processing operation. Storage Unit: Primary Memory: It is volatile ( loses data on power ...

Describe the four basic data types. How could we extend the range of values they represent?

Answer: The basic four data types are: Data Type Integer Type Character Type Floating Point Type Void Type signed int short int long int unsigned unsigned int unsigned short int unsigned long int char signed char unsigned char float double long double