Chapter 2 : Arrays : Notes #1

1.  Define an Array ?

An array is a collection of elements of the same type placed in contiguous memory locations. Arrays are used to store a set of values of the same type under a single variable name.


2. How can we declare an array ?

The syntax for declaring an array in C++ is as follows.
data_type array_name[size];

In the syntax, data_type is the type of data that the array variable can store,
array_name is an identifier for naming the array and the size is a positive integernumber that specifies the number of elements in the array. 

The following is anexample:

 int num[10];
The above statement declares an array named num that can store 10 integer numbers.Each item in an array is called an element of the array.


3. In C++, the array index starts with_____________?

zero

4. Array index is also called as  ______________ ?

subscript

5. What is array initialization ?


Array elements can be initialized in their declaration statements in the same manner as in the case of variables, except that the values must be included in braces, as shown in the following examples:
int score[5] = {98, 87, 92, 79, 85};
char code[6] = {‘s’, ‘a’, ‘m’, ‘p’, ‘l’, ‘e’};
float wgpa[7] = {9.60, 6.43, 8.50, 8.65, 5.89, 7.56, 8.22};



Comments

  1. Thanks for this. I really like what you've posted here and wish you the best of luck with this blog and thanks for sharing. NBA Betting Predictions Today

    ReplyDelete

Post a Comment