SlideShare une entreprise Scribd logo
1  sur  14
Made By :
Aditya Kaushik
Department :
Computer Engineering (A1)
Gandhinagar Institute of Technology
Khatraj-Kalol Road,
Gandhinagar
www.git.org.in
What is an array ?!
An array is a collection of elements of the same
type that are referenced by a common name .
It is a derived data type compared to the basic
data types (int , float and char) .
All elements of an array occupy a set of
contiguous memory locations.
Imagine declaring the marks of 100 students by
using normal variable declaration !
Something like this :
void main()
int studMark;
{
int studMarks1, studMarks2 ,studMarks3 ,
studMarks4, ..., ..., studMarks99,
studMarks100;
...
...
return 0;
}
By using an array , we can just declare like this
int studMark [100];
This will reserve 100 contiguous memory
locations for storing student’s marks.
Graphically, this can be depicted as in the
following figure .
Array has simplified our declaration of the
variables.
We can use index or subscript to identify each
element or location in the memory.
For example, studMark[0] will refer to the
first element of the array.
Thus by changing the value of Index, we could
refer to any element in the array.
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 initialization simply means giving initial
values to an array , it must be initialized at the
time of declaration.
Initialization of an array may take the fllwing
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'};
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.
C compiler automatically creates an array which
is big enough to hold all the initializer.
Arrays allow programmers to group related items
of the same data type in one variable.
However, when referring to an array, one has to
specify not only the array or variable name but also
the index number of interest.
Program example 1: Sum of array’s element.
Notice the array's element which is not
initialized is set to 0 automatically.
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 xInteger[3][4];
float matrixNum[20][25];
If we assign initial string values for the 2D array it
will look something like the following,
char Name[6][10] = {"Mr. Bean", "Mr. Bush",
"Nicole", "Kidman", "Arnold", "Jodie"};
Here, we can initialize the array with 6 strings,
each with maximum 9 characters long.
It would look something like this.
Take note that for strings the null character (0)
still needed.
The array size is = First index * second index = xy.
This stands true for all dimensions of array .
for e.g. 3-Dimensional array;
array_name[x][y][z]; First index * second index * third
index = xyz
The contents of the array in memory after the
three strings are read in the array.
Re-run the program, enter the following data:
“you”, “my”. Illustrates the content as done
previously.
The End. 

Contenu connexe

Tendances

Tendances (20)

2D Array
2D Array 2D Array
2D Array
 
Array in C
Array in CArray in C
Array in C
 
Array in (C) programing
Array in (C) programing Array in (C) programing
Array in (C) programing
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Strings Functions in C Programming
Strings Functions in C ProgrammingStrings Functions in C Programming
Strings Functions in C Programming
 
Arrays
ArraysArrays
Arrays
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Array Of Pointers
Array Of PointersArray Of Pointers
Array Of Pointers
 
Strings in C
Strings in CStrings in C
Strings in C
 
Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
 
String in c programming
String in c programmingString in c programming
String in c programming
 
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
 
Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
ARRAY
ARRAYARRAY
ARRAY
 
Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in C
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
Unit 1 introduction to data structure
Unit 1   introduction to data structureUnit 1   introduction to data structure
Unit 1 introduction to data structure
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
 

En vedette

Lab 5 array
Lab 5 arrayLab 5 array
Lab 5 array
mkazree
 
Contributor ppt
Contributor pptContributor ppt
Contributor ppt
Shan Gupta
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
Neveen Reda
 

En vedette (14)

Array in c language
Array in c languageArray in c language
Array in c language
 
Arrays
ArraysArrays
Arrays
 
Array in c
Array in cArray in c
Array in c
 
Lab 5 array
Lab 5 arrayLab 5 array
Lab 5 array
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
 
CPD engage deeply git swami vivekananda gtu unit 9
CPD engage deeply git swami vivekananda gtu unit 9CPD engage deeply git swami vivekananda gtu unit 9
CPD engage deeply git swami vivekananda gtu unit 9
 
Least squares estimators
Least squares estimatorsLeast squares estimators
Least squares estimators
 
Lab exp declaring arrays)
Lab exp declaring arrays)Lab exp declaring arrays)
Lab exp declaring arrays)
 
Contributor ppt
Contributor pptContributor ppt
Contributor ppt
 
Array in c
Array in cArray in c
Array in c
 
Types of lamps
Types of lampsTypes of lamps
Types of lamps
 
The scope of contribution
The scope of contributionThe scope of contribution
The scope of contribution
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
 

Similaire à Array in C

cprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.pptcprogrammingarrayaggregatetype.ppt
cprogrammingarrayaggregatetype.ppt
Samitbiswas10
 
cprogrammingarrayaggregatetype (1).ppt
cprogrammingarrayaggregatetype (1).pptcprogrammingarrayaggregatetype (1).ppt
cprogrammingarrayaggregatetype (1).ppt
karunapatel13
 

Similaire à Array in C (20)

3.ArraysandPointers.pptx
3.ArraysandPointers.pptx3.ArraysandPointers.pptx
3.ArraysandPointers.pptx
 
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 concept
Array conceptArray concept
Array concept
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
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
 
Arrays
ArraysArrays
Arrays
 
Arrays In C
Arrays In CArrays In C
Arrays In C
 
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
 
Arrays
ArraysArrays
Arrays
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
 
Arrays
ArraysArrays
Arrays
 
ARRAYS
ARRAYSARRAYS
ARRAYS
 
Array and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdfArray and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdf
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
 
Array&string
Array&stringArray&string
Array&string
 
Array lecture
Array lectureArray lecture
Array lecture
 

Dernier

Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 

Dernier (20)

Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 

Array in C

  • 1. Made By : Aditya Kaushik Department : Computer Engineering (A1) Gandhinagar Institute of Technology Khatraj-Kalol Road, Gandhinagar www.git.org.in
  • 2. What is an array ?! An array is a collection of elements of the same type that are referenced by a common name . It is a derived data type compared to the basic data types (int , float and char) . All elements of an array occupy a set of contiguous memory locations.
  • 3. Imagine declaring the marks of 100 students by using normal variable declaration ! Something like this : void main() int studMark; { int studMarks1, studMarks2 ,studMarks3 , studMarks4, ..., ..., studMarks99, studMarks100; ... ... return 0; }
  • 4. By using an array , we can just declare like this int studMark [100]; This will reserve 100 contiguous memory locations for storing student’s marks. Graphically, this can be depicted as in the following figure .
  • 5. Array has simplified our declaration of the variables. We can use index or subscript to identify each element or location in the memory. For example, studMark[0] will refer to the first element of the array. Thus by changing the value of Index, we could refer to any element in the array.
  • 6. 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.
  • 7. Array initialization simply means giving initial values to an array , it must be initialized at the time of declaration. Initialization of an array may take the fllwing 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'};
  • 8. 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. C compiler automatically creates an array which is big enough to hold all the initializer.
  • 9. Arrays allow programmers to group related items of the same data type in one variable. However, when referring to an array, one has to specify not only the array or variable name but also the index number of interest. Program example 1: Sum of array’s element. Notice the array's element which is not initialized is set to 0 automatically.
  • 10. 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 xInteger[3][4]; float matrixNum[20][25];
  • 11. If we assign initial string values for the 2D array it will look something like the following, char Name[6][10] = {"Mr. Bean", "Mr. Bush", "Nicole", "Kidman", "Arnold", "Jodie"}; Here, we can initialize the array with 6 strings, each with maximum 9 characters long. It would look something like this.
  • 12. Take note that for strings the null character (0) still needed. The array size is = First index * second index = xy. This stands true for all dimensions of array . for e.g. 3-Dimensional array; array_name[x][y][z]; First index * second index * third index = xyz
  • 13. The contents of the array in memory after the three strings are read in the array. Re-run the program, enter the following data: “you”, “my”. Illustrates the content as done previously.