• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Lecture17 arrays.ppt
 

Lecture17 arrays.ppt

on

  • 8,657 views

arrays in c

arrays in c

Statistics

Views

Total Views
8,657
Views on SlideShare
8,657
Embed Views
0

Actions

Likes
0
Downloads
373
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Lecture17 arrays.ppt Lecture17 arrays.ppt Presentation Transcript

    • Prakash KhaireLecturer, B V Patel Institute of BMC & ITARRAYS
    • Arrays●It is derived data type●Arrays are collection of data that belong tosame data type●Arrays are collection of homogeneous data●Array elements can be accessed by its positionin the array called as index●Values in an array are identified using arrayname with subscripts●Also known as subscripted variable●It is fixed-size collection of elements
    • ● Following are types of array●One-dimensional Array●Two-dimensional Array●Multi-dimensional Array
    • One-dimensional Array●A collections of variables are given one variable nameusing only one subscript and such a variable is called asingle-subscripted variable or one dimensional array●Syntax data_type ArrayName[size]; data_type : is a valid data type like int, float or char Arrayname : is a valid identifier size : maximum number of elements that can be stored in array
    • ArraysArray index starts with zeroThe last index in an array is num – 1 wherenum is the no of elements in a arrayint a[9] is an array that stores 9 integers index 0 1 2 3 4 5 6 7 8 elementsMemory address 100 102 104 106 108 110 112 114 116
    • Initilization of Array●After declaring the array, all the elements ofarray must be initialized other wise they willcontain garbage value●At compile time●At run time data_type ArrayName[size] = {list of values}int marks[5] = {55, 63,67,78,59};
    • Each value is treated as an element of the arrayand is stored in the memory as follows marks 55 0 63 1 67 2 78 3 59 4
    • ●float marks[5]={45.5,65.0,67.5.77.0,79 .0};●char name[8]={‘P’,’r’,’a’, ’k’, ’a’, ’s’, ’h’, ’0’};●int marks[] = {63,68,57,69,77};●char name[] = “Prakash”;
    • int marks[5]={67,66};● 67 0 66 1 4646 2 8978 3 -545 4
    • Two Dimensional Array●To store following data of 4 students 201 202 203 204 205 09BCA07 45 42 41 56 46 09BCA14 46 55 70 49 56 09BCA45 65 61 68 42 56 09BCA115 46 38 39 45 42
    • Two Dimensional Array ● StudentDetailsIJ ● Where, StudentDetails represents a matrix I represents no. of rows J represents no. of columns It is collection of rows and columns
    • Two Dimensional Array ● Declaration of 2D array type array_name[row_size][column_size]; column0 column1 column2 column3 column4 Row0 0,0 0,1 0,2 0,3 0,4 Row1 1,0 1,1 1,2 1,3 1,4 Row2 2,0 2,1 2,2 2,3 2,4 Row3 3,0 3,1 3,2 3,3 3,4
    • Storage Representation● Similar to 1D Array, 2D array are also stored in contiguous memory in increasing memory locations.0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2990 992 994 996 998 1000 1002 1004 1006
    • Initilization● int mat[3][3] = { 1,3,2,4,7,6,5,8,9};● int mat[3][3] = { {1,3,2}, {4,7,6}, {5,8,9} };
    • ● int mat[ ][3]={ {1,3,2}, {4,7,6}, {5,8,9} };
    • int mat[3][3] = { {0}, {0}, {0} };● int mat[3][3] = { {1}, {7,6}, {5} }; int mat[3][3] = { {0}, {0}, {0} };
    • ● int mat[3][3] = { 0,0,0};