Variable Initialization in C, C language Assignment Help

Assignment Help: >> Introduction to C language >> Variable Initialization in C, C language

Variable Initialization in C

 Variables can be declared or initialized using an assignment operator '='.

Syntax: variable name =constant

OR

data_type variable_name = constant

Example:-

1. int i;   i = 10;

2. int i = 10;

3. int a = 12;        int b = 30;

4. int a = 12, b = 30;

A programming situation may arise where several variable have to be initialized to the same value.

Example1:

int a = 10, b = 10, c = 10, d = 10, x = 10, y = 10;

Instead of this we can use the following expressions:

Example2:

                int a, b, c, d, x, y;

                a = b = c = d = x = y = 10;

                However the following statement is valid:

Example3:

             int a = b = c = d = x = y = 10;

                This is because a variable cannot initialize another variable until it has been declared earlier.

Example4:

                int a = 10;

                int b = a;

int c = b;

int d = c;

int x = d;

int y = x;

These statements are perfectly acceptable since when 'b' is initialized to value of 'a', variable 'a' had already been known to the compiler.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd