Write down about the initialization of one dimensional array

Initialization of one dimensional array :  After an array is declared, its elements must be initialized. An array can be initialized either of the following stages,

§  At compile time.
§  At run time.

Compile time initialization : User can initialize the elements of an array in the same way as the ordinary variables when they are declared. This is compile time initialization. The general form is as follows,

                   type array_name[size]={list of values};

The values in the list are separated by commas. For example,

                   int number[3]={0,0,0};

This will declare the variable number as an array of size 3 and will assign 0 to each element.
Run time initialization : An array can be explicitly initialized at run time. This approach is usually applied for initializing large arrays. For example,

The first 50 elements of the array sum are initialized to zero while the remaining 50 elements are initialized to 1.0 at run time.

Author: Tanmay Chakrabarty

Tanmay Chakrabarty is a former CSE student, currently working as a Senior Software Engineer with 5+ years of experience in the field of Web Application development in PHP+MySQL platform with strong skills in Javascript, JQuery, JQuery UI and CSS. He tries to write notes every week but fails due to heavy loads of duty.

Recommended Recommends


Contact Us