C++ arrays part1

1,322 views

Published on

array in c++ programming, array in c++ tutorial, array in c++ syntax, array in c++ example

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,322
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
96
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

C++ arrays part1

  1. 1. Arrays Author – Subhasis Nayak
  2. 2. What Is an Array? <ul><li>An array is a sequential collection of data storage locations , each of which holds the same type of data. Each storage location is called an element of the array . </li></ul>Each one is called as an element Storage amount 0 Storage amount 1 Storage amount 2 Storage amount 4 Storage amount 5 Storage amount 6
  3. 3. Continue …. <ul><li>An array is a collection of variables of the same type that are referred to through a common name . </li></ul><ul><li>Arrays are collections of variables , each having the same name but possessing a unique number called a subscript . </li></ul><ul><li>A specific element in an array is accessed by an index . </li></ul>
  4. 4. Continue …… <ul><li>I sometimes love to say arrays families of variables —of the same data type , such as int or string, stored in the computer’s memory. </li></ul><ul><li>Each member of the collection has the same name but possesses a unique number called a subscript , which is used to identify it . Individual members of an array are called elements of the array. </li></ul>
  5. 5. Declaring an array <ul><li>You declare an array by writing the certain type </li></ul><ul><li>It will followed by the array name (array identifier) and subscript. </li></ul><ul><li>Next, the subscript is the number of elements in the array. </li></ul><ul><li>Subscript surrounded by the square brackets ‘ [] ’. Number of elements will be in square brackets. </li></ul>
  6. 6. Let’s declare an array. <ul><li>If I want to declare an array of integer type having name numeric & it has 10 elements. I will write like this </li></ul>int numeric[10];
  7. 7. Little backend concept. <ul><li>As we know an compiler allocates 2 byte of space to store integer type of value, so here to store our array numeric compiler will allocates 20 bytes of memory space to the array. </li></ul><ul><li>Array is a sequential collection of data storage locations. Each element of numeric array is an individual integer. </li></ul>
  8. 8. Do you know ? Do you know array starts from ‘0’. It means the first value will be stored at 0 th place.
  9. 9. Two big things in array. <ul><li>Index = This is the number which is unique . Through which we distinguish the each element of an array. </li></ul><ul><li>Index value = Each element in an array has a different index value, which are sequential integers starting from 0. </li></ul><ul><li>It may possible to store same value to two different index but it is never possible having similar index number. </li></ul>
  10. 10. Continue. ….
  11. 11. Accessing Array Elements <ul><li>You access an array element by referring to its offset or it’s index from the beginning of the array. </li></ul><ul><li>You can’t an index value in your program that’s outside the legal range for an array. </li></ul><ul><li>Some compiler doesn’t inform you about that, so you have the problem at run time. </li></ul><ul><li>So, be specific about you’re the array range. </li></ul>
  12. 12. Index & memory address Here this array memory allocation started at ‘1000’ and proceeds
  13. 13. Program 01(initialization separatly )
  14. 14. Program 02(initialization with declaration)
  15. 15. Program 03(initializing through a loop)
  16. 16. Program 04(adding two arrays)
  17. 17. Program 04(Display in reverse ord..)

×