Define single dimensional array?
Answers
Answered by
0
You can just say 'array'.
An array is a collection of similar data type.
Eg: An array of integers.
An array cannot contain two different data type.
Why array are important/ Advantages of using them?
Like just think about a real life example. If you want to store roll numbers of 100 student in your program.
One thing you can do is, create 100 variables of integer and store roll numbers in them. Now just how messed up code will be. 100 lines of code just for creating the variables and then if you want to print all the roll numbers, 100 more lines of code. Don't you think, this is the worst possible solution.
Now l, do the same with array.
int arr[100];
That's it! You just created 100 variables for storing 100 roll numbers.
Now for printing all the roll numbers.
for(int i=0;i<100;i++) {
cout<<arr[i];
}
Just look at the code now. Those 200 lines of code in 4 lines. I think it's enough for now to justify why array are awesome.
An array is a collection of similar data type.
Eg: An array of integers.
An array cannot contain two different data type.
Why array are important/ Advantages of using them?
Like just think about a real life example. If you want to store roll numbers of 100 student in your program.
One thing you can do is, create 100 variables of integer and store roll numbers in them. Now just how messed up code will be. 100 lines of code just for creating the variables and then if you want to print all the roll numbers, 100 more lines of code. Don't you think, this is the worst possible solution.
Now l, do the same with array.
int arr[100];
That's it! You just created 100 variables for storing 100 roll numbers.
Now for printing all the roll numbers.
for(int i=0;i<100;i++) {
cout<<arr[i];
}
Just look at the code now. Those 200 lines of code in 4 lines. I think it's enough for now to justify why array are awesome.
Similar questions