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”); } |
Always with you to fascinate and feisty you.I'm blessed and I thank God for every day for everything that happens for me.
Monday, July 28, 2014
Array based Qs and answers
Subscribe to:
Post Comments (Atom)
अच्छे विचार करे विचार
पहचान की नुमाईश, जरा कम करें... जहाँ भी "मैं" लिखा है, उसे "हम" करें... हमारी "इच्छाओं" से ज़्यादा "सुन...
-
Program 1:- Write a function in C++ that exchanges data (passing by references )using swap function to interchange the given tw...
-
Directions: In each Q1 to Q3 of the following questions, there are five letter groups or words in each question. Four of these letter g...
-
#include<stdio.h> #include<conio.h> void main() { int a[10],b[10],c[10]; int n,k,i,p,coeff; clrscr(); for(i=0;i<1...
No comments:
Post a Comment