SlideShare a Scribd company logo
1 of 17
(Managed By Shree Tapi Brahmcharyashram Sabha)
Shree Swami AtmanandVidhya Sankul, Kapodra,Varachha Road, Surat, Gujarat, India. 395006
Phone: 0261-2573552 Fax No.: 0261-2573554 Email: ssasit@yahoo.in Web: www.ssasit.ac.in
Shree Swami Atmanand Saraswati Institute of Technology,
Surat
Arrays1
Presented by:
Patel Raj G
Arrays2
Arrays
 Suppose, you need to store years of 100 cars. Will you define
100 variables?
int y1, y2,…, y100;
 An array is an indexed data structure to represent several
variables having the same data type: int y[100];
3
y[0] y[1] y[2] … y[k-1] y[k] y[k+1] … y[98] y[99]
One-Dimensional Arrays (cont’d)
 An element of an array is accessed using the array name
and an index or subscript, for example: y[5] which can be
used like a variable
 In C, the subscripts always start with 0 and increment by 1,
so y[5] is the sixth element
 The name of the array is the address of the first element
and the subscript is the offset
4
y[0] y[1] y[2] … y[k-1] y[k] y[k+1] … y[98] y[99]
Definition and Initialization
 An array is defined using a declaration statement.
data_type array_name[size];
allocates memory for size elements
subscript of first element is 0
subscript of last element is size-1
size must be a constant
5
Example
int list[5];
 allocates memory for 5 integer variables
 subscript of first element is 0
 subscript of last element is 4
 C does not check bounds on arrays
 list[6] =5; /* may give segmentation fault or overwrite
other memory locations*/
6
list[0]
list[1]
list[2]
list[3]
list[4]
Initializing Arrays
 Arrays can be initialized at the time they are declared.
 Examples:
double rate[3] ={0.15, 0.25, 0.3};
char list[5] = {‘h’, ’e’, ’l’, ’l’, ’o’};
double vector[100] = {0.0}; /* assigns
zero to all 100 elements */
int s[] = {5,0,-5}; /*the size of s is 3*/
7
Assigning values to an array8
For loops are often used to assign values to an array
Example:
int list[5], i;
for(i=0; i<5; i++){
list[i] = i;
}
list[0]
list[3]
list[4]
list[1]
list[2]
0
1
2
3
4
list[0]
list[1]
list[2]
list[3]
list[4]
OR
for(i=0; i<=4; i++){
list[i] = i;
}
Matrices (2D-array)
 A matrix is a set of numbers arranged in a grid with rows and
columns.
 A matrix is defined using a type declaration statement.
datatype array_name[row_size][column_size];
int matrix[3][4];
9
in memory
Column 0 Column 1 Column 2 Column 3
Row 0
Row 1
Row 2
4
1
0
2
-1
2
4
3
0
-1
3
1
4 1 0 2
-1 2 4 3
0 -1 3 1
Accessing Array Elements
int matrix[3][4];
 matrix has 12 integer elements
 matrix[0][0] element in first row, first column
 matrix[2][3] element in last row, last column
 matrix is the address of the first element
 matrix[1] is the address of the Row 1
 matrix[1] is a one dimensional array (Row 1)
10
Initialization
int x[4][4] = { {2, 3, 7, 2},
{7, 4, 5, 9},
{5, 1, 6, -3},
{2, 5, -1, 3}};
int x[][4] = { {2, 3, 7, 2},
{7, 4, 5, 9},
{5, 1, 6, -3},
{2, 5, -1, 3}};
11
Initialization
int i, j, matrix[3][4];
for (i=0; i<3; i++)
for (j=0; j<4; j++)
matrix[i][j] = i;
12
j
0 1 2 3
0
1
2
i
0 0 0 0
1 1 1 1
2 2 2 2
j
0 1 2 3
0
1
2
i
0 1 2 3
0 1 2 3
0 1 2 3
matrix[i][j] = j;
Multidimensional Arrays
 An array can have many dimensions – if it has more than
one dimension, it is called a multidimensional array
 Each dimension subdivides the previous one into the
specified number of elements
 Each dimension has its own length constant
 Because each dimension is an array of array references,
the arrays within one dimension can be of different lengths
these are sometimes called ragged arrays
13
Strings
 A string is an array of characters
char data[10] = “Hello”;
char data2[] = {‘H’, ‘e’, ‘l’, ‘l’, ‘o’, ‘0’}
 Use printf to print strings
printf(“%s”,data);
 Can be accessed char by char
data[0] is first character
14
H e l l o 0
0 1 2 3 4 5 6 7 8 9
data
End of String
Symbol
Strings
 Each character has an integer representation
15
a b c d e z…………
97 98 99 100 101 ………………………112
A B C D E Z…………
65 66 67 68 69 ……………………… 90
0 1 2 3 4 98765
48 49 50 51 52 53 54 55 56 57
0
0
n
10
Strings
 Characters can be interpreted as integers
char c = ‘A’;
printf(“%c n”,c);
prints A
printf(“%d n”,c);
prints 65
Printf(“%c n”,65);
prints A
16
17

More Related Content

What's hot (19)

Multi-Dimensional Lists
Multi-Dimensional ListsMulti-Dimensional Lists
Multi-Dimensional Lists
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
 
2D arrays
2D arrays2D arrays
2D arrays
 
Algo>Arrays
Algo>ArraysAlgo>Arrays
Algo>Arrays
 
Fuzzy sets
Fuzzy setsFuzzy sets
Fuzzy sets
 
Arrays
ArraysArrays
Arrays
 
Chap1 array
Chap1 arrayChap1 array
Chap1 array
 
List , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonList , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in python
 
Day 4a iteration and functions.pptx
Day 4a   iteration and functions.pptxDay 4a   iteration and functions.pptx
Day 4a iteration and functions.pptx
 
Array
ArrayArray
Array
 
Day 4b iteration and functions for-loops.pptx
Day 4b   iteration and functions  for-loops.pptxDay 4b   iteration and functions  for-loops.pptx
Day 4b iteration and functions for-loops.pptx
 
2D-Array
2D-Array 2D-Array
2D-Array
 
bobok
bobokbobok
bobok
 
Python Lecture 11
Python Lecture 11Python Lecture 11
Python Lecture 11
 
Working with arrays in php
Working with arrays in phpWorking with arrays in php
Working with arrays in php
 
Basic R Data Manipulation
Basic R Data ManipulationBasic R Data Manipulation
Basic R Data Manipulation
 
Trie tree
Trie treeTrie tree
Trie tree
 
Coding test review
Coding test reviewCoding test review
Coding test review
 
Trie (1)
Trie (1)Trie (1)
Trie (1)
 

Similar to Array (20)

Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional
 
Array
ArrayArray
Array
 
SP-First-Lecture.ppt
SP-First-Lecture.pptSP-First-Lecture.ppt
SP-First-Lecture.ppt
 
Lecture 15 - Array
Lecture 15 - ArrayLecture 15 - Array
Lecture 15 - Array
 
Array
ArrayArray
Array
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
Data structure array
Data structure  arrayData structure  array
Data structure array
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
Arrays
ArraysArrays
Arrays
 
Arrays
ArraysArrays
Arrays
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Chapter 13.pptx
Chapter 13.pptxChapter 13.pptx
Chapter 13.pptx
 
Comp102 lec 8
Comp102   lec 8Comp102   lec 8
Comp102 lec 8
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
 
Array in C.pdf
Array in C.pdfArray in C.pdf
Array in C.pdf
 
Array.pdf
Array.pdfArray.pdf
Array.pdf
 
Arrays
ArraysArrays
Arrays
 
2DArrays.ppt
2DArrays.ppt2DArrays.ppt
2DArrays.ppt
 

More from Patel Raj

disposal of solid waste
disposal of solid waste disposal of solid waste
disposal of solid waste Patel Raj
 
Inner Product Space
Inner Product SpaceInner Product Space
Inner Product SpacePatel Raj
 
Communication Skill
Communication SkillCommunication Skill
Communication SkillPatel Raj
 
Water resources
Water  resourcesWater  resources
Water resourcesPatel Raj
 
Nanorobotics13.ppt
Nanorobotics13.pptNanorobotics13.ppt
Nanorobotics13.pptPatel Raj
 

More from Patel Raj (6)

disposal of solid waste
disposal of solid waste disposal of solid waste
disposal of solid waste
 
Hydrography
HydrographyHydrography
Hydrography
 
Inner Product Space
Inner Product SpaceInner Product Space
Inner Product Space
 
Communication Skill
Communication SkillCommunication Skill
Communication Skill
 
Water resources
Water  resourcesWater  resources
Water resources
 
Nanorobotics13.ppt
Nanorobotics13.pptNanorobotics13.ppt
Nanorobotics13.ppt
 

Recently uploaded

(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 

Recently uploaded (20)

(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 

Array

  • 1. (Managed By Shree Tapi Brahmcharyashram Sabha) Shree Swami AtmanandVidhya Sankul, Kapodra,Varachha Road, Surat, Gujarat, India. 395006 Phone: 0261-2573552 Fax No.: 0261-2573554 Email: ssasit@yahoo.in Web: www.ssasit.ac.in Shree Swami Atmanand Saraswati Institute of Technology, Surat Arrays1
  • 3. Arrays  Suppose, you need to store years of 100 cars. Will you define 100 variables? int y1, y2,…, y100;  An array is an indexed data structure to represent several variables having the same data type: int y[100]; 3 y[0] y[1] y[2] … y[k-1] y[k] y[k+1] … y[98] y[99]
  • 4. One-Dimensional Arrays (cont’d)  An element of an array is accessed using the array name and an index or subscript, for example: y[5] which can be used like a variable  In C, the subscripts always start with 0 and increment by 1, so y[5] is the sixth element  The name of the array is the address of the first element and the subscript is the offset 4 y[0] y[1] y[2] … y[k-1] y[k] y[k+1] … y[98] y[99]
  • 5. Definition and Initialization  An array is defined using a declaration statement. data_type array_name[size]; allocates memory for size elements subscript of first element is 0 subscript of last element is size-1 size must be a constant 5
  • 6. Example int list[5];  allocates memory for 5 integer variables  subscript of first element is 0  subscript of last element is 4  C does not check bounds on arrays  list[6] =5; /* may give segmentation fault or overwrite other memory locations*/ 6 list[0] list[1] list[2] list[3] list[4]
  • 7. Initializing Arrays  Arrays can be initialized at the time they are declared.  Examples: double rate[3] ={0.15, 0.25, 0.3}; char list[5] = {‘h’, ’e’, ’l’, ’l’, ’o’}; double vector[100] = {0.0}; /* assigns zero to all 100 elements */ int s[] = {5,0,-5}; /*the size of s is 3*/ 7
  • 8. Assigning values to an array8 For loops are often used to assign values to an array Example: int list[5], i; for(i=0; i<5; i++){ list[i] = i; } list[0] list[3] list[4] list[1] list[2] 0 1 2 3 4 list[0] list[1] list[2] list[3] list[4] OR for(i=0; i<=4; i++){ list[i] = i; }
  • 9. Matrices (2D-array)  A matrix is a set of numbers arranged in a grid with rows and columns.  A matrix is defined using a type declaration statement. datatype array_name[row_size][column_size]; int matrix[3][4]; 9 in memory Column 0 Column 1 Column 2 Column 3 Row 0 Row 1 Row 2 4 1 0 2 -1 2 4 3 0 -1 3 1 4 1 0 2 -1 2 4 3 0 -1 3 1
  • 10. Accessing Array Elements int matrix[3][4];  matrix has 12 integer elements  matrix[0][0] element in first row, first column  matrix[2][3] element in last row, last column  matrix is the address of the first element  matrix[1] is the address of the Row 1  matrix[1] is a one dimensional array (Row 1) 10
  • 11. Initialization int x[4][4] = { {2, 3, 7, 2}, {7, 4, 5, 9}, {5, 1, 6, -3}, {2, 5, -1, 3}}; int x[][4] = { {2, 3, 7, 2}, {7, 4, 5, 9}, {5, 1, 6, -3}, {2, 5, -1, 3}}; 11
  • 12. Initialization int i, j, matrix[3][4]; for (i=0; i<3; i++) for (j=0; j<4; j++) matrix[i][j] = i; 12 j 0 1 2 3 0 1 2 i 0 0 0 0 1 1 1 1 2 2 2 2 j 0 1 2 3 0 1 2 i 0 1 2 3 0 1 2 3 0 1 2 3 matrix[i][j] = j;
  • 13. Multidimensional Arrays  An array can have many dimensions – if it has more than one dimension, it is called a multidimensional array  Each dimension subdivides the previous one into the specified number of elements  Each dimension has its own length constant  Because each dimension is an array of array references, the arrays within one dimension can be of different lengths these are sometimes called ragged arrays 13
  • 14. Strings  A string is an array of characters char data[10] = “Hello”; char data2[] = {‘H’, ‘e’, ‘l’, ‘l’, ‘o’, ‘0’}  Use printf to print strings printf(“%s”,data);  Can be accessed char by char data[0] is first character 14 H e l l o 0 0 1 2 3 4 5 6 7 8 9 data End of String Symbol
  • 15. Strings  Each character has an integer representation 15 a b c d e z………… 97 98 99 100 101 ………………………112 A B C D E Z………… 65 66 67 68 69 ……………………… 90 0 1 2 3 4 98765 48 49 50 51 52 53 54 55 56 57 0 0 n 10
  • 16. Strings  Characters can be interpreted as integers char c = ‘A’; printf(“%c n”,c); prints A printf(“%d n”,c); prints 65 Printf(“%c n”,65); prints A 16
  • 17. 17