SlideShare a Scribd company logo
1 of 5
Arrays
What you’ll learn:
o Defining and using arrays
o Defining and using strings
What is an array ?
 An array is a collection of variables of the same type that are referenced by a common
name.
 They are a derived data type.
 We can divide arrays into two types:
 Single Dimensional (1-D) arrays
 Multi Dimensional arrays
Single Dimensional Arrays
1 2 3
int arr [5] = { 1, 2, 3, 4, 5 };
Syntax: base_type array_name [size];
Size
Array name Initialization
Base Type
Memory:
4000 4016 4020
4 5
4004
Total Size:
4 X 5 = 20
Multi Dimensional Arrays
1 2 3 4 5
int arr [3][2] = { {1,2}, {3,4}, {5,6} };
Syntax: base_type array_name [rows][columns];
Size
Array name Initialization
Base Type
Memory
4000 4020 4024
6
4004
Total Size:
4 X 6 = 24
1 2
3 4
5 6
4008
4016
4000
Strings
‘H’ ‘e’ ‘l’ ‘l’
char str[] = “Hello”;
Syntax: char array_name [size];
Size
String name Initialization
Memory:
4000 4005 4006
‘o’ ‘0’
4001
Total Size:
1 X 6 = 6

More Related Content

What's hot

What's hot (20)

Array
ArrayArray
Array
 
Array in (C) programing
Array in (C) programing Array in (C) programing
Array in (C) programing
 
Arrays
ArraysArrays
Arrays
 
Arrays In C
Arrays In CArrays In C
Arrays In C
 
arrays of structures
arrays of structuresarrays of structures
arrays of structures
 
Array in c
Array in cArray in c
Array in c
 
Array c programming
Array c programmingArray c programming
Array c programming
 
One Dimensional Array
One Dimensional Array One Dimensional Array
One Dimensional Array
 
Algorithm and Data Structure - Array and Struct
Algorithm and Data Structure - Array and StructAlgorithm and Data Structure - Array and Struct
Algorithm and Data Structure - Array and Struct
 
Array in c++
Array in c++Array in c++
Array in c++
 
2 d array
2 d array2 d array
2 d array
 
R data structures-2
R data structures-2R data structures-2
R data structures-2
 
R Data Structures (Part 1)
R Data Structures (Part 1)R Data Structures (Part 1)
R Data Structures (Part 1)
 
R data-structures-3
R data-structures-3R data-structures-3
R data-structures-3
 
#Jai c presentation
#Jai c presentation#Jai c presentation
#Jai c presentation
 
SPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in CSPL 10 | One Dimensional Array in C
SPL 10 | One Dimensional Array in C
 
Array,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN CArray,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN C
 
Unit4 C
Unit4 C Unit4 C
Unit4 C
 
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
 
Array,data type
Array,data typeArray,data type
Array,data type
 

Viewers also liked

8.derived data types
8.derived data types8.derived data types
8.derived data typesHardik gupta
 
3.looping(iteration statements)
3.looping(iteration statements)3.looping(iteration statements)
3.looping(iteration statements)Hardik gupta
 
1.getting started with c
1.getting started with c1.getting started with c
1.getting started with cHardik gupta
 
Programming & Data Structure Lecture Notes
Programming & Data Structure Lecture NotesProgramming & Data Structure Lecture Notes
Programming & Data Structure Lecture NotesFellowBuddy.com
 

Viewers also liked (8)

6.operators
6.operators6.operators
6.operators
 
5.functions
5.functions5.functions
5.functions
 
8.derived data types
8.derived data types8.derived data types
8.derived data types
 
3.looping(iteration statements)
3.looping(iteration statements)3.looping(iteration statements)
3.looping(iteration statements)
 
2.decision making
2.decision making2.decision making
2.decision making
 
7.pointers
7.pointers7.pointers
7.pointers
 
1.getting started with c
1.getting started with c1.getting started with c
1.getting started with c
 
Programming & Data Structure Lecture Notes
Programming & Data Structure Lecture NotesProgramming & Data Structure Lecture Notes
Programming & Data Structure Lecture Notes
 

Similar to ArraysExplainedSingleMultiDimensionalStrings

Similar to ArraysExplainedSingleMultiDimensionalStrings (20)

Array
ArrayArray
Array
 
Arrays
ArraysArrays
Arrays
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Arrays
ArraysArrays
Arrays
 
Array , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptxArray , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptx
 
Chapter 4 (Part I) - Array and Strings.pdf
Chapter 4 (Part I) - Array and Strings.pdfChapter 4 (Part I) - Array and Strings.pdf
Chapter 4 (Part I) - Array and Strings.pdf
 
Arrays
ArraysArrays
Arrays
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
Array
ArrayArray
Array
 
ARRAY
ARRAYARRAY
ARRAY
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
 
BHARGAVIARRAY.PPT.pptx
BHARGAVIARRAY.PPT.pptxBHARGAVIARRAY.PPT.pptx
BHARGAVIARRAY.PPT.pptx
 
Learn Java Part 9
Learn Java Part 9Learn Java Part 9
Learn Java Part 9
 
Lecture 15 - Array
Lecture 15 - ArrayLecture 15 - Array
Lecture 15 - Array
 
Arrays.pptx
Arrays.pptxArrays.pptx
Arrays.pptx
 
Array lecture
Array lectureArray lecture
Array lecture
 
Arrays
ArraysArrays
Arrays
 
Array
ArrayArray
Array
 
Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and strings
 

ArraysExplainedSingleMultiDimensionalStrings

  • 1. Arrays What you’ll learn: o Defining and using arrays o Defining and using strings
  • 2. What is an array ?  An array is a collection of variables of the same type that are referenced by a common name.  They are a derived data type.  We can divide arrays into two types:  Single Dimensional (1-D) arrays  Multi Dimensional arrays
  • 3. Single Dimensional Arrays 1 2 3 int arr [5] = { 1, 2, 3, 4, 5 }; Syntax: base_type array_name [size]; Size Array name Initialization Base Type Memory: 4000 4016 4020 4 5 4004 Total Size: 4 X 5 = 20
  • 4. Multi Dimensional Arrays 1 2 3 4 5 int arr [3][2] = { {1,2}, {3,4}, {5,6} }; Syntax: base_type array_name [rows][columns]; Size Array name Initialization Base Type Memory 4000 4020 4024 6 4004 Total Size: 4 X 6 = 24 1 2 3 4 5 6 4008 4016 4000
  • 5. Strings ‘H’ ‘e’ ‘l’ ‘l’ char str[] = “Hello”; Syntax: char array_name [size]; Size String name Initialization Memory: 4000 4005 4006 ‘o’ ‘0’ 4001 Total Size: 1 X 6 = 6

Editor's Notes

  1. Hello