Current Affairs

Arrays – Computer – C – Programming

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  :  
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.
Ex: 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.
Ex: 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.   
Ex: int a[10];  For(i=0;i<10;i++) Printf(“%dn”,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.
Ex:  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.
Ex: 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]; 

About the author


Leave a Comment

error: Content is protected !!