Documents

Arrays

Description
programming
Categories
Published
of 16
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Related Documents
Share
Transcript
  Principles of Programming - NI2005 1 Chapter 8: Arrays In this chapter, you will learn about Introduction to Array  Array declaration  Array initialization  Assigning values to array elements Reading values from array elements Passing array to function 2 Dimensional arrays Simple Searching  Principles of Programming - NI2005 2 Introduction to Array In C, a group of items of the same type can be set up using Array  An array is a group of consecutive memory locations related by the fact that they all have the same name and the same type. The compiler must reserve storage (space) for each element/item of a declared array. The size of an array is static (fixed) throughout program execution. To refer to a particular location or element in the array, we specify the name of the array (index or subscript) and the position number of the particular element in the array.  Principles of Programming - NI2005 3 Let say we have an array called a.  -10 99 -8 100 27 10 1976 -2020 1 a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8]  Name of the array The position number within the square brackets is formally called a subscript  . A subscript can be an integer or an integer expression. For example if x = 1 and y = 2, then a[x+y] is equal to a[3].  Notice that the position starts from 0.  Principles of Programming - NI2005 4  Array Declaration  Array declaration is made by specifying the data type , it’s name and the number of space (size)  so that the computer may reserve the appropriate amount of memory. General syntax: data_type array_name[size]; Examples: int my_array[100]; char name[20]; double bigval[5*200]; int a[27], b[10], c[76];
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks