Q&A for Previous Year Questions Subject: Computer Programming (B.Tech. I Year)
------------------------------------------------------------------------------------------------------------------------------------------
1
UNIT–III:
Arrays: Introduction, One-dimensional arrays, Declaring and Initializing arrays,
Multidimensional arrays.
Strings: Introduction to Strings, String operations with and without using String handling
functions, Array of strings
1. What is an array? How to declare and initialize arrays? Explain with examples
Ans: Array:-
An array is defined as an ordered set of similar data items. All the data items of an array are
stored in consecutive memory locations in RAM. The elements of an array are of same data type
and each item can be accessed using the same name.
Declaration of an array:- We know that all the variables are declared before they are used in
the program. Similarly, an array must be declared before it is used. During declaration, the size
of the array has to be specified. The size used during declaration of the array informs the
compiler to allocate and reserve the specified memory locations.
Syntax:- data_type array_name[n];
where, n is the number of data items (or) index(or) dimension.
0 to (n-1) is the range of array.
Ex: int a[5];
float x[10];
Initialization of Arrays:-
The different types of initializing arrays:
1. At Compile time
(i) Initializing all specified memory locations.
(ii) Partial array initialization
(iii) Initialization without size.
(iv) String initialization.
2. At Run Time
1. Compile Time Initialization
We can initialize the elements of arrays in the same way as the ordinary variables when they are
declared. The general form of initialization of arrays is