SlideShare a Scribd company logo
1 of 12
Bhagwan mahavir college of
Engg. & Technology
Sub:Computer Programming &
Utilization(210003)
Class:Civil-c
Active Learning on :
Array
Year :Winter 2016-17
Guided By: Nisha
Bhanderi
Group Members:
1.Krunal koladiya-160060106060
2.Jay mandani-160060106069
3.Parth diyora-160060106502
4.Fenil Soni-160060106159
Index
 Introduction
 One Dimension Array
 Two Dimension Array
ARRAY
 An array is a collection of elements of the same type
that are referenced by a common name.
 Compared to the basic data type (int, float & char) it is
an aggregate or derived data type.
 All the elements of an array occupy a set of contiguous
memory locations.
ARRAY
 This absolutely has simplified our declaration of the
variables.
 We can use index or subscript to identify each
element or location in the memory.
 Hence, if we have an index of jIndex,
studMark[jIndex] would refer to the jIndexth
element in the array of studMark.
 For example, studMark[0] will refer to the first
element of the array.
 Thus by changing the value of jIndex, we could
refer to any element in the array.
 So, array has simplified our declaration and of
course, manipulation of the data.
ARRAY
One Dimensional Array: Declaration
 Dimension refers to the array's size, which is how big the
array is.
 A single or one dimensional array declaration has the
following form,
array_element_data_type array_name[array_size];
 Here, array_element_data_type define the base type of
the array, which is the type of each element in the array.
 array_name is any valid C / C++ identifier name that
obeys the same rule for the identifier naming.
 array_size defines how many elements the array will
hold.
ARRAY
 Examples of the one-dimensional array declarations,
int xNum[20], yNum[50];
float fPrice[10], fYield;
char chLetter[70];
 The first example declares two arrays named xNum and yNum of type
int. Array xNum can store up to 20 integer numbers while yNum can
store up to 50 numbers.
 The second line declares the array fPrice of type float. It can store up to
10 floating-point values.
 fYield is basic variable which shows array type can be declared together
with basic type provided the type is similar.
 The third line declares the array chLetter of type char. It can store a
string up to 69 characters.
 Why 69 instead of 70? Remember, a string has a null terminating
character (0) at the end, so we must reserve for it.
ARRAYArray Initialization
 An array may be initialized at the time of declaration.
 Giving initial values to an array.
 Initialization of an array may take the following form,
type array_name[size] = {a_list_of_value};
 For example:
int idNum[7] = {1, 2, 3, 4, 5, 6, 7};
float fFloatNum[5] = {5.6, 5.7, 5.8, 5.9, 6.1};
char chVowel[6] = {'a', 'e', 'i', 'o', 'u', '0'};
 The first line declares an integer array idNum and it immediately
assigns the values 1, 2, 3, ..., 7 to idNum[0], idNum[1], idNum[2],...,
idNum[6] respectively.
 The second line assigns the values 5.6 to fFloatNum[0], 5.7 to
fFloatNum[1], and so on.
 Similarly the third line assigns the characters 'a' to chVowel[0], 'e' to
chVowel[1], and so on. Note again, for characters we must use the
single apostrophe/quote (') to enclose them.
 Also, the last character in chVowel is NULL character ('0').
ARRAY
 Initialization of an array of type char for holding strings may take the
following form,
char array_name[size] = "string_lateral_constant";
 For example, the array chVowel in the previous example could have
been written more compactly as follows,
char chVowel[6] = "aeiou";
 When the value assigned to a character array is a string (which must be
enclosed in double quotes), the compiler automatically supplies the
NULL character but we still have to reserve one extra place for the
NULL.
 For unsized array (variable sized), we can lare as follow,
char chName[ ] = "Mr. Dracula";
 C compiler automatically creates an array which is big enough to hold
all the initializer.
ARRAY
Two Dimensional/2D Arrays
 A two dimensional array has two subscripts/indexes.
 The first subscript refers to the row, and the second, to the
column.
 Its declaration has the following form,
data_type array_name[1st
dimension size][2nd
dimension size];
 For examples,
int x Integer[3][4];
float matrixNum[20][25];
 The first line declares xInteger as an integer array with 3 rows
and 4 columns.
 Second line declares a matrixNum as a floating-point array with
20 rows and 25 columns.
12

More Related Content

What's hot (20)

Array
ArrayArray
Array
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
 
Arrays
ArraysArrays
Arrays
 
Module7
Module7Module7
Module7
 
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
 
C string
C stringC string
C string
 
Strings in C
Strings in CStrings in C
Strings in C
 
String in c
String in cString in c
String in c
 
Lecture 15 - Array
Lecture 15 - ArrayLecture 15 - Array
Lecture 15 - Array
 
Array Of Pointers
Array Of PointersArray Of Pointers
Array Of Pointers
 
C++ programming (Array)
C++ programming (Array)C++ programming (Array)
C++ programming (Array)
 
strings in c language and its importance
strings in c language and its importancestrings in c language and its importance
strings in c language and its importance
 
Operation on string presentation
Operation on string presentationOperation on string presentation
Operation on string presentation
 
Strings Functions in C Programming
Strings Functions in C ProgrammingStrings Functions in C Programming
Strings Functions in C Programming
 
05 c++-strings
05 c++-strings05 c++-strings
05 c++-strings
 
Arrays
ArraysArrays
Arrays
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
 
String in programming language in c or c++
 String in programming language  in c or c++  String in programming language  in c or c++
String in programming language in c or c++
 
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
 

Viewers also liked

M9. industrialisasi dan perkembangan sektor industri
M9. industrialisasi dan perkembangan sektor industriM9. industrialisasi dan perkembangan sektor industri
M9. industrialisasi dan perkembangan sektor industrierlina na
 
M5. perubahan struktur ekonomi
M5. perubahan struktur ekonomiM5. perubahan struktur ekonomi
M5. perubahan struktur ekonomierlina na
 
M8. peranan sektor pertanian
M8. peranan sektor pertanianM8. peranan sektor pertanian
M8. peranan sektor pertanianerlina na
 
M3. sistem ekonomi indonesia
M3. sistem ekonomi indonesiaM3. sistem ekonomi indonesia
M3. sistem ekonomi indonesiaerlina na
 
M6. kemiskinan&kesenjangan pendapatan
M6. kemiskinan&kesenjangan pendapatanM6. kemiskinan&kesenjangan pendapatan
M6. kemiskinan&kesenjangan pendapatanerlina na
 
M4. pertumbuhan ekonomi
M4. pertumbuhan ekonomiM4. pertumbuhan ekonomi
M4. pertumbuhan ekonomierlina na
 
M13. modal asing & utang ln
M13. modal asing & utang lnM13. modal asing & utang ln
M13. modal asing & utang lnerlina na
 
M12. neraca pembayaran
M12. neraca pembayaranM12. neraca pembayaran
M12. neraca pembayaranerlina na
 
M7. pembangunan ekonomi daerah
M7. pembangunan ekonomi daerahM7. pembangunan ekonomi daerah
M7. pembangunan ekonomi daeraherlina na
 
Artificial intelligence bsc - iso 27001 information security
Artificial intelligence   bsc - iso 27001 information securityArtificial intelligence   bsc - iso 27001 information security
Artificial intelligence bsc - iso 27001 information securityUfuk Cebeci
 
M11. prospek ukm dalam perdagangan bebas
M11. prospek ukm dalam perdagangan bebasM11. prospek ukm dalam perdagangan bebas
M11. prospek ukm dalam perdagangan bebaserlina na
 
M2. sejarah perekonomian indonesia
M2. sejarah perekonomian indonesiaM2. sejarah perekonomian indonesia
M2. sejarah perekonomian indonesiaerlina na
 
Las apps
Las appsLas apps
Las appsHoy Hoy
 
Mechanical Spider - Robotics Course Details
Mechanical Spider  - Robotics Course DetailsMechanical Spider  - Robotics Course Details
Mechanical Spider - Robotics Course DetailsAcademy of Robotics
 
Spider Research Projects
Spider Research ProjectsSpider Research Projects
Spider Research Projectsmm17
 
Spider 1.0
Spider 1.0Spider 1.0
Spider 1.0vr1988
 

Viewers also liked (18)

M9. industrialisasi dan perkembangan sektor industri
M9. industrialisasi dan perkembangan sektor industriM9. industrialisasi dan perkembangan sektor industri
M9. industrialisasi dan perkembangan sektor industri
 
M5. perubahan struktur ekonomi
M5. perubahan struktur ekonomiM5. perubahan struktur ekonomi
M5. perubahan struktur ekonomi
 
M8. peranan sektor pertanian
M8. peranan sektor pertanianM8. peranan sektor pertanian
M8. peranan sektor pertanian
 
M10. ukm
M10. ukmM10. ukm
M10. ukm
 
M3. sistem ekonomi indonesia
M3. sistem ekonomi indonesiaM3. sistem ekonomi indonesia
M3. sistem ekonomi indonesia
 
M6. kemiskinan&kesenjangan pendapatan
M6. kemiskinan&kesenjangan pendapatanM6. kemiskinan&kesenjangan pendapatan
M6. kemiskinan&kesenjangan pendapatan
 
M4. pertumbuhan ekonomi
M4. pertumbuhan ekonomiM4. pertumbuhan ekonomi
M4. pertumbuhan ekonomi
 
M13. modal asing & utang ln
M13. modal asing & utang lnM13. modal asing & utang ln
M13. modal asing & utang ln
 
M12. neraca pembayaran
M12. neraca pembayaranM12. neraca pembayaran
M12. neraca pembayaran
 
M7. pembangunan ekonomi daerah
M7. pembangunan ekonomi daerahM7. pembangunan ekonomi daerah
M7. pembangunan ekonomi daerah
 
Jornal digital 29 12-16
Jornal digital 29 12-16Jornal digital 29 12-16
Jornal digital 29 12-16
 
Artificial intelligence bsc - iso 27001 information security
Artificial intelligence   bsc - iso 27001 information securityArtificial intelligence   bsc - iso 27001 information security
Artificial intelligence bsc - iso 27001 information security
 
M11. prospek ukm dalam perdagangan bebas
M11. prospek ukm dalam perdagangan bebasM11. prospek ukm dalam perdagangan bebas
M11. prospek ukm dalam perdagangan bebas
 
M2. sejarah perekonomian indonesia
M2. sejarah perekonomian indonesiaM2. sejarah perekonomian indonesia
M2. sejarah perekonomian indonesia
 
Las apps
Las appsLas apps
Las apps
 
Mechanical Spider - Robotics Course Details
Mechanical Spider  - Robotics Course DetailsMechanical Spider  - Robotics Course Details
Mechanical Spider - Robotics Course Details
 
Spider Research Projects
Spider Research ProjectsSpider Research Projects
Spider Research Projects
 
Spider 1.0
Spider 1.0Spider 1.0
Spider 1.0
 

Similar to Arrays cpu2 (20)

3.ArraysandPointers.pptx
3.ArraysandPointers.pptx3.ArraysandPointers.pptx
3.ArraysandPointers.pptx
 
Module 4- Arrays and Strings
Module 4- Arrays and StringsModule 4- Arrays and Strings
Module 4- Arrays and Strings
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
 
cprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.pptcprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.ppt
 
cprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.pptcprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.ppt
 
cprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.pptcprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.ppt
 
cprogrammingarrayaggregatetype (1).ppt
cprogrammingarrayaggregatetype (1).pptcprogrammingarrayaggregatetype (1).ppt
cprogrammingarrayaggregatetype (1).ppt
 
Array in C
Array in CArray in C
Array in C
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
Chap 7(array)
Chap 7(array)Chap 7(array)
Chap 7(array)
 
ARRAYS
ARRAYSARRAYS
ARRAYS
 
C programming , array 2020
C programming , array 2020C programming , array 2020
C programming , array 2020
 
Unit ii data structure-converted
Unit  ii data structure-convertedUnit  ii data structure-converted
Unit ii data structure-converted
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
 
Arrays
ArraysArrays
Arrays
 
C%20ARRAYS.pdf.pdf
C%20ARRAYS.pdf.pdfC%20ARRAYS.pdf.pdf
C%20ARRAYS.pdf.pdf
 
Comp102 lec 8
Comp102   lec 8Comp102   lec 8
Comp102 lec 8
 
Strings Arrays
Strings ArraysStrings Arrays
Strings Arrays
 
Array
ArrayArray
Array
 
Unit 2
Unit 2Unit 2
Unit 2
 

Recently uploaded

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 

Recently uploaded (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 

Arrays cpu2

  • 1. Bhagwan mahavir college of Engg. & Technology Sub:Computer Programming & Utilization(210003) Class:Civil-c
  • 2. Active Learning on : Array Year :Winter 2016-17 Guided By: Nisha Bhanderi
  • 3. Group Members: 1.Krunal koladiya-160060106060 2.Jay mandani-160060106069 3.Parth diyora-160060106502 4.Fenil Soni-160060106159
  • 4. Index  Introduction  One Dimension Array  Two Dimension Array
  • 5. ARRAY  An array is a collection of elements of the same type that are referenced by a common name.  Compared to the basic data type (int, float & char) it is an aggregate or derived data type.  All the elements of an array occupy a set of contiguous memory locations.
  • 6. ARRAY  This absolutely has simplified our declaration of the variables.  We can use index or subscript to identify each element or location in the memory.  Hence, if we have an index of jIndex, studMark[jIndex] would refer to the jIndexth element in the array of studMark.  For example, studMark[0] will refer to the first element of the array.  Thus by changing the value of jIndex, we could refer to any element in the array.  So, array has simplified our declaration and of course, manipulation of the data.
  • 7. ARRAY One Dimensional Array: Declaration  Dimension refers to the array's size, which is how big the array is.  A single or one dimensional array declaration has the following form, array_element_data_type array_name[array_size];  Here, array_element_data_type define the base type of the array, which is the type of each element in the array.  array_name is any valid C / C++ identifier name that obeys the same rule for the identifier naming.  array_size defines how many elements the array will hold.
  • 8. ARRAY  Examples of the one-dimensional array declarations, int xNum[20], yNum[50]; float fPrice[10], fYield; char chLetter[70];  The first example declares two arrays named xNum and yNum of type int. Array xNum can store up to 20 integer numbers while yNum can store up to 50 numbers.  The second line declares the array fPrice of type float. It can store up to 10 floating-point values.  fYield is basic variable which shows array type can be declared together with basic type provided the type is similar.  The third line declares the array chLetter of type char. It can store a string up to 69 characters.  Why 69 instead of 70? Remember, a string has a null terminating character (0) at the end, so we must reserve for it.
  • 9. ARRAYArray Initialization  An array may be initialized at the time of declaration.  Giving initial values to an array.  Initialization of an array may take the following form, type array_name[size] = {a_list_of_value};  For example: int idNum[7] = {1, 2, 3, 4, 5, 6, 7}; float fFloatNum[5] = {5.6, 5.7, 5.8, 5.9, 6.1}; char chVowel[6] = {'a', 'e', 'i', 'o', 'u', '0'};  The first line declares an integer array idNum and it immediately assigns the values 1, 2, 3, ..., 7 to idNum[0], idNum[1], idNum[2],..., idNum[6] respectively.  The second line assigns the values 5.6 to fFloatNum[0], 5.7 to fFloatNum[1], and so on.  Similarly the third line assigns the characters 'a' to chVowel[0], 'e' to chVowel[1], and so on. Note again, for characters we must use the single apostrophe/quote (') to enclose them.  Also, the last character in chVowel is NULL character ('0').
  • 10. ARRAY  Initialization of an array of type char for holding strings may take the following form, char array_name[size] = "string_lateral_constant";  For example, the array chVowel in the previous example could have been written more compactly as follows, char chVowel[6] = "aeiou";  When the value assigned to a character array is a string (which must be enclosed in double quotes), the compiler automatically supplies the NULL character but we still have to reserve one extra place for the NULL.  For unsized array (variable sized), we can lare as follow, char chName[ ] = "Mr. Dracula";  C compiler automatically creates an array which is big enough to hold all the initializer.
  • 11. ARRAY Two Dimensional/2D Arrays  A two dimensional array has two subscripts/indexes.  The first subscript refers to the row, and the second, to the column.  Its declaration has the following form, data_type array_name[1st dimension size][2nd dimension size];  For examples, int x Integer[3][4]; float matrixNum[20][25];  The first line declares xInteger as an integer array with 3 rows and 4 columns.  Second line declares a matrixNum as a floating-point array with 20 rows and 25 columns.
  • 12. 12