google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.: Array based Qs and answers

Monday, July 28, 2014

Array based Qs and answers

1) What is an array?

Answer:-
An array is a group of data of the same data type stored in successive storage locations.



2)How are elements of an array accessed?

Answer:-
Elements of an array are accessed using subscripts.



3)What is a subscript?

Answer:-
A subscript or an index is a positive integer value that identifies the storage position of
an element in the array.



4)Which is the smallest subscript?

Answer:-
0 (zero)



5)How many subscripts does a one and two dimensional array have?

Answer:-
one dimensional array has one subscript and a two dimensional array has two
subscripts( row and a column subscript).



6)Write the syntax for declaring a one dimensional array.

Answer:-
syntax: datatype arrayname [size];



7) Write the syntax for declaring a two dimensional array.

Answer:-
Syntax: datatype arrayname [row size] [column size];



8) What do you mean by initializing an array?

Answer:-
Initializing of an array means storing data in to an array at the design time.



9) How one dimensional array is initialized?

Answer:-
The initialization can be done two ways –
• Initialization at design level- in this method of initialization the data values are
stored in to the array at the time of array declaration. 
Example: 
int a [0]={10,-50,20,300,5};
• Initialization at run time- to initialize an array at run time means to input data values
in to the array at the time of execution of the program.
Example:
int a[10];
for (i=0;i<10;i++)
scanf(“%d”,&a[i]);



10) How to output the elements of one dimensional array?

Answer:-
To print elements of an array a for loop is used.
Example:
int a[10];
for(i=0;i<10;i++)
printf(“%d\n”,a[i]);



11) How two dimensional arrays are initialized?

Answer:-
• initialization at design time- the data element are stored in to the array at the time
of declaration of the array. The elements of each row and each column are
represented within the pair of flower brackets.
Example : int a[3][3]={1,3,5,3,7,82,5,8};
• initialization of the array at the time of execution- to input data in to two
dimensional array, two for loops are used foe every value of the outer loop index.
The inner loop is executed a specified number of times.
Example: int a[4][5];
for(i=0;i<4;i++)
for(j=0;j<5;j++)
scanf(“%d”,&a[i][j]);



12) How do you print a matrix? Give ex.

Answer:-
A two dimensional array can be printed as follows-
int a[3][4];
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
printf(“%d\t”,a[i][j]);
}
printf(“\n”);
}





No comments:

Post a Comment

शिव भोलेनाथ स्तुति

 जय शिवशंकर, जय गंगाधर, करुणा-कर करतार हरे,   जय कैलाशी, जय अविनाशी, सुखराशि, सुख-सार हरे जय शशि-शेखर, जय डमरू-धर जय-जय प्रेमागार हरे,   जय ...