array1 - Computer Programming TA C162 Arrays in C An array...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Computer Programming TA C162 Second Semester 2008-2009 Arrays in C An array is fixed size sequenced collection of elements of the same data type addressable by index or subscript. It is a convenient structure for representing large number of homogenous values It can be used to represent a list of numbers or a list of names. Examples: Linear arrays List of marks of students List of grades of students List of employees in an organization List of names of students
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Computer Programming TA C162 Second Semester 2008-2009 Introduction How do we allocate a group of memory locations? • character string table of numbers How about this? Not too bad, but… What if there are 100 numbers? • How do we write a loop to process each number? Fortunately, C gives us a better way -- the array . int num0; int num1; int num2; int num3;
Background image of page 2
3 Computer Programming TA C162 Second Semester 2008-2009 Memory Allocation for Arrays Array • Group of consecutive memory locations Same name and type Structures of related data items • Static entity – same size throughout program To refer to an element, specify • Array name Position number E.g. ar[9] ar[6] -45 6 0 72 548 -89 0 62 -3 1 ar[0] ar[1] ar[2] ar[3] ar[9] ar[8] ar[7] ar[5] ar[4]
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Computer Programming TA C162 Second Semester 2008-2009 One Dimensional Arrays: Declaration List of items given one variable name using only one subscript Declaration: type variable_name[size]; Here size indicates the maximum number of elements The subscript value start from 0 to size-1 Example: int number[10]; float number[10]; char grade[10];
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/14/2010 for the course CS SS ZG653 taught by Professor Shanta during the Spring '09 term at Birla Institute of Technology & Science.

Page1 / 15

array1 - Computer Programming TA C162 Arrays in C An array...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online