Contact:-9447974300

Chapter-2. ARRAYS

1.  What is an Array?

Arrays are used to store a set of values of the same type under a single variable name. It is a collection of same type elements placed in contiguous memory locations. Each element in an array can be accessed using its position in the list, called index number or subscript. Eg: char a[10];

2. Write array declarations for the following:

a. Scores of 100 students : int score[100];

b. English letters : char a[10];

c. A list of 10 years : int year[12];

d. A list of 30 real numbers : float n[30];

3. What is array initialization?

Giving values to the array elements at the time of array declaration is known as array initialization.

4. Write array initialization statements for the following:

a. An array of 10 scores: 89, 75, 82, 93, 78, 95, 81, 88, 77,and 82

Ans: int score[10] = {89, 75, 82, 93, 78, 95, 81, 88, 77, 82};

b.An array with the letters of VIBGYOR.

Ans: char c[7]={‘V’,’I’,’B’,’G’,’Y’,’O’,’R’};

5. Write a C++ code to input values into the array: int ar[50];

int i;

for(i=0;i<50;i++)

{

cout<<”Enter value”;

cin<<ar[i];

7. What is array traversal?

Accessing each element of an array at least once to perform any operation is known as traversal operation. Eg. Displaying all elements of an array.

8. Consider the array declaration int a[3]={2,3,4}; What is the value of a[1]?

3

9. How is memory allocated for a single dimensional array?

The elements of a single dimensional array will store in continues memory locations

according to its data type

Eg. int n[5]; Here consider n[0] is in the memory location of address 1000. An integer

data need 2 bytes of memory. So n[1] will be at1002, n[2] at 1004 and so on.

10. Read the following statements:

char name[20];

cin>>name;

cout<<name;

What will be the output if you input the string “Sachin Tendulkar”? Justify your answer.

Sachin. The letters of the word Sachin is stores in the array name as first 6 char elements. The input is completed due to the blank space and the word Tendulkar is skipped.

11. A string can be considered as an array of ——.

Characters.

12. A ———- is stored at the end of the string.

          null character    ‘\0’

13.Write a Program to read n elements to an array and find the largest element

#include<iostream> 

using namespace std;

int main()

{    int a[100],n,i,Large;

cout<<“Enter the Limit”;

cin>>n;

cout<<“Enter the elements”<<“\n”;

for(i=0;i<=n;i++)

{    cin>>a[i];  }

Large=a[0];

for(i=1;i<=n;i++)

{  if(a[i]>Large)

{  Large=a[i];  }

else

{  Large=Large;  }   }

cout<<“The Largest number is “<<Large;

}

14.What is meant by traversal?

Accessing each element of the array atleast once is called traversal.

15.How does puts(“hello”); differ from cout<<”hello”;?

Puts(“hello”); will display “hello”. It print’\n’ after the string.

Cout<<”hello”; will display “hello”. There is no ‘\n’ after the string.

16.What is the use of get() function?

17. The elements of an array  with ten elements are numbered from __0__ to __9__.

18. An array element is accessed using   

Ans: Index number or subscript.

19. If   AR is an array, which element will be referenced using  AR[7]?

Ans: 6th element of array AR

20. Consider the array declaration  int a[3]={2,3,4};  What is the value of  a[1]?

Ans:

21. Consider the array declaration  int a[]={1,2,4};What is the value of  a[1]?

Ans:2

22. Printing all the elements of an array is an example for _____ operation.

Ans: Traversal

23. Write down the output of the following code segment:

puts(“hello”);

puts(“friends”);

Ans: hellofriends

24. Write the initialization statement to store the string “GCC”.

Ans: char str[ ] = “GCC”;

25. What does the declaration  int studlist[1000];mean?

Ans: int studlist[1000];

The above statement declare an array named studlist that can store 1000 integer numbers.

About the Author

Leave a Reply