SlideShare a Scribd company logo
C Array
An array is defined as the collection of similar type of
data items stored at contiguous memory locations.
Arrays are the derived data type in C programming
language which can store the primitive type of data
such as int, char, double, float, etc
Advantage of C Array
1) Code Optimization: Less code to the access the data.
2) Ease of traversing: By using the for loop, we can retrieve
the elements of an array easily.
3) Ease of sorting: To sort the elements of the array, we need
a few lines of code only.
4) Random Access: We can access any element randomly
using the array.
Disadvantage of C Array
1) Fixed Size: Whatever size, we define at the time of
declaration of the array, we can't exceed the limit. So, it
doesn't grow the size dynamically like LinkedList which we will
learn later.
Declaration of C
Array
data_type array_name[array_size];
Eg- int marks[5];
Initialization of C Array
marks[0]=80;
marks[1]=60;
marks[2]=70;
marks[3]=85;
marks[4]=75;
int marks[5]={20,30,40,50,60};
Program to declare & Initialize Array
Program for character Array initialization & Declaration
Program for addition of all array elements
Program to find smallest array element
Program for addition of all Odd array elements
Classification of Array
Single Dimentional Array Representation
Multidimentional Array
Two dimensional arrays
•At times we need to store the data in form of tables or matrices. For this, we can use the
two dimensional arrays.
•This array is specified by using two subscripts where one subscript is denoted as the row
and the other as the column.
•It is also viewed as an array of arrays.
2- Dimentional Array Representation
Declaration of a two-dimensional array
data_type array_name [row_size] [column_size] ;
The declaration of the rows and columns is compulsory for a
two-dimensional array.
We cannot replace the row size with the column size and the
column size to row size. The proper sequence has to be
maintained
int score[3][2] ;
Initialization of 2D array
1. int score [3][2] ={50, 60, 70, 95, 3, 36};
2. int score [3][2] ={{50, 60} , {70,95} ,{3,36}};
3. score[0][0] = 50;
score [0][1] = 60;
score[1][0] = 70 ;
score [1][1] = 95;
score[2][0] = 3;
score [2][1] = 36;
2-D Array Declaration & Initialization
2-D Array Element modification
Program for addition of all elements in 2-D Array
Linear Search
A linear search, also known as a sequential search, is a method of finding an element within a
list. It checks each element of the list sequentially until a match is found or the whole list has
been searched
Program to search array element using Linear Search
Passing array to function
In C programming, you can pass an entire array to
functions In C programming, you can pass an entire array
to functions
Passing array to function
String
A string in C is array of characters.
The string can be defined as the one-dimensional array of characters terminated by a
NULL ('0’).
The string is used to manipulate text such as word or sentences.
The termination character ('0') / NULL character: -The termination character ('0') is
important in a string since it is only way to identify where the string ends.
Built in Functions
#include <stdio.h>
#include <string.h>
int main()
{
char a[20]="Program";
char b[20]={'P','r','o','g','r','a','m','0'};
printf("Length of string a = %d n",strlen(a));
printf("Length of string b = %d n",strlen(b));
return 0;
}
String Length (strlen)
#include <stdio.h>
#include <string.h>
int main() {
char str1[20] = "C programming";
char str2[20];
// copying str1 to str2
strcpy(str2, str1);
puts(str2); // C programming
return 0;
}
String Copy(strcpy)
#include <string.h>
int main() {
char str1[100] = "Welcome to ", str2[] = "RIT";
// concatenates str1 and str2
// the resultant string is stored in str1.
strcat(str1, str2);
puts(str1);
puts(str2);
return 0;
}
String Concat (strcat)
#include <string.h>
int main()
{
char str1[100] = "c programming...";
printf("%s",strupr(str1));
}
String Upper Case (strupr)
#include <string.h>
int main()
{
char str1[100] = "WELCOME TO RIT";
printf("%s",strlwr(str1));
}
String Lower Case (strlwr)
The strcmp() compares two strings character by character. If the strings are equal, the function retu
otherwise returns 1.
String Compare (strcmp)
#include <stdio.h>
#include <string.h>
int main() {
char str1[] = "abcd", str2[] = "abCd", str3[] = "abcd";
int result;
// comparing strings str1 and str2
result = strcmp(str1, str2);
printf("strcmp(str1, str2) = %dn", result);
// comparing strings str1 and str3
result = strcmp(str1, str3);
printf("strcmp(str1, str3) = %dn", result);
return 0;
}
Problem statements for Lab
Array.pptx
Array.pptx

More Related Content

Similar to Array.pptx

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
Appili Vamsi Krishna
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
AntareepMajumder
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
nmahi96
 
Arrays & Strings.pptx
Arrays & Strings.pptxArrays & Strings.pptx
Arrays & Strings.pptx
AnkurRajSingh2
 
Array&amp;string
Array&amp;stringArray&amp;string
Array&amp;string
chanchal ghosh
 
fundamentals of c programming_String.pptx
fundamentals of c programming_String.pptxfundamentals of c programming_String.pptx
fundamentals of c programming_String.pptx
JStalinAsstProfessor
 
Arrays
ArraysArrays
C UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYC UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYRajeshkumar Reddy
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
YOGESH SINGH
 
Unitii classnotes
Unitii classnotesUnitii classnotes
Unitii classnotes
Sowri Rajan
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
Rakesh Roshan
 
Unit 3 arrays and_string
Unit 3 arrays and_stringUnit 3 arrays and_string
Unit 3 arrays and_string
kirthika jeyenth
 
Learn C# Programming - Nullables & Arrays
Learn C# Programming - Nullables & ArraysLearn C# Programming - Nullables & Arrays
Learn C# Programming - Nullables & Arrays
Eng Teong Cheah
 
Arrays In C
Arrays In CArrays In C
Arrays In C
yndaravind
 
Module 4- Arrays and Strings
Module 4- Arrays and StringsModule 4- Arrays and Strings
Module 4- Arrays and Strings
nikshaikh786
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
HNDE Labuduwa Galle
 

Similar to Array.pptx (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
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
 
Arrays & Strings.pptx
Arrays & Strings.pptxArrays & Strings.pptx
Arrays & Strings.pptx
 
Array&amp;string
Array&amp;stringArray&amp;string
Array&amp;string
 
fundamentals of c programming_String.pptx
fundamentals of c programming_String.pptxfundamentals of c programming_String.pptx
fundamentals of c programming_String.pptx
 
Arrays
ArraysArrays
Arrays
 
C UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYC UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDY
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
 
Unit ii data structure-converted
Unit  ii data structure-convertedUnit  ii data structure-converted
Unit ii data structure-converted
 
Unitii classnotes
Unitii classnotesUnitii classnotes
Unitii classnotes
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
Unit 3 arrays and_string
Unit 3 arrays and_stringUnit 3 arrays and_string
Unit 3 arrays and_string
 
Learn C# Programming - Nullables & Arrays
Learn C# Programming - Nullables & ArraysLearn C# Programming - Nullables & Arrays
Learn C# Programming - Nullables & Arrays
 
Session 7 En
Session 7 EnSession 7 En
Session 7 En
 
Session 7 En
Session 7 EnSession 7 En
Session 7 En
 
Arrays In C
Arrays In CArrays In C
Arrays In C
 
Module 4- Arrays and Strings
Module 4- Arrays and StringsModule 4- Arrays and Strings
Module 4- Arrays and Strings
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
 

More from SwapnaliPawar27

10.Design Of Two Pass Assembler in system software.pdf
10.Design Of Two Pass Assembler in system software.pdf10.Design Of Two Pass Assembler in system software.pdf
10.Design Of Two Pass Assembler in system software.pdf
SwapnaliPawar27
 
9.SimpleAssemblyScheme in system software.pdf
9.SimpleAssemblyScheme in system software.pdf9.SimpleAssemblyScheme in system software.pdf
9.SimpleAssemblyScheme in system software.pdf
SwapnaliPawar27
 
8.PassStructureofAssembler in System Software.pdf
8.PassStructureofAssembler in System Software.pdf8.PassStructureofAssembler in System Software.pdf
8.PassStructureofAssembler in System Software.pdf
SwapnaliPawar27
 
7.IntermediateCode in System Software.pdf
7.IntermediateCode in System Software.pdf7.IntermediateCode in System Software.pdf
7.IntermediateCode in System Software.pdf
SwapnaliPawar27
 
6.Assembly Language Statments in system Software.pdf
6.Assembly Language Statments in system Software.pdf6.Assembly Language Statments in system Software.pdf
6.Assembly Language Statments in system Software.pdf
SwapnaliPawar27
 
5.Elements of Assembly Language in System Software.pdf
5.Elements of Assembly Language in System Software.pdf5.Elements of Assembly Language in System Software.pdf
5.Elements of Assembly Language in System Software.pdf
SwapnaliPawar27
 
4.LanguageProcessors and language Processing Activities.pdf
4.LanguageProcessors and language Processing Activities.pdf4.LanguageProcessors and language Processing Activities.pdf
4.LanguageProcessors and language Processing Activities.pdf
SwapnaliPawar27
 
3.SystemPrograms and System Programming.pdf
3.SystemPrograms and System Programming.pdf3.SystemPrograms and System Programming.pdf
3.SystemPrograms and System Programming.pdf
SwapnaliPawar27
 
2.Exploring-the-Goals-and-Programs-of-System-Software.pdf
2.Exploring-the-Goals-and-Programs-of-System-Software.pdf2.Exploring-the-Goals-and-Programs-of-System-Software.pdf
2.Exploring-the-Goals-and-Programs-of-System-Software.pdf
SwapnaliPawar27
 
Inroduction System Software -features Types
Inroduction System Software -features TypesInroduction System Software -features Types
Inroduction System Software -features Types
SwapnaliPawar27
 
2.dfa.pdf
2.dfa.pdf2.dfa.pdf
2.dfa.pdf
SwapnaliPawar27
 
1.AutomataU1.pdf
1.AutomataU1.pdf1.AutomataU1.pdf
1.AutomataU1.pdf
SwapnaliPawar27
 
Pointer.pptx
Pointer.pptxPointer.pptx
Pointer.pptx
SwapnaliPawar27
 

More from SwapnaliPawar27 (13)

10.Design Of Two Pass Assembler in system software.pdf
10.Design Of Two Pass Assembler in system software.pdf10.Design Of Two Pass Assembler in system software.pdf
10.Design Of Two Pass Assembler in system software.pdf
 
9.SimpleAssemblyScheme in system software.pdf
9.SimpleAssemblyScheme in system software.pdf9.SimpleAssemblyScheme in system software.pdf
9.SimpleAssemblyScheme in system software.pdf
 
8.PassStructureofAssembler in System Software.pdf
8.PassStructureofAssembler in System Software.pdf8.PassStructureofAssembler in System Software.pdf
8.PassStructureofAssembler in System Software.pdf
 
7.IntermediateCode in System Software.pdf
7.IntermediateCode in System Software.pdf7.IntermediateCode in System Software.pdf
7.IntermediateCode in System Software.pdf
 
6.Assembly Language Statments in system Software.pdf
6.Assembly Language Statments in system Software.pdf6.Assembly Language Statments in system Software.pdf
6.Assembly Language Statments in system Software.pdf
 
5.Elements of Assembly Language in System Software.pdf
5.Elements of Assembly Language in System Software.pdf5.Elements of Assembly Language in System Software.pdf
5.Elements of Assembly Language in System Software.pdf
 
4.LanguageProcessors and language Processing Activities.pdf
4.LanguageProcessors and language Processing Activities.pdf4.LanguageProcessors and language Processing Activities.pdf
4.LanguageProcessors and language Processing Activities.pdf
 
3.SystemPrograms and System Programming.pdf
3.SystemPrograms and System Programming.pdf3.SystemPrograms and System Programming.pdf
3.SystemPrograms and System Programming.pdf
 
2.Exploring-the-Goals-and-Programs-of-System-Software.pdf
2.Exploring-the-Goals-and-Programs-of-System-Software.pdf2.Exploring-the-Goals-and-Programs-of-System-Software.pdf
2.Exploring-the-Goals-and-Programs-of-System-Software.pdf
 
Inroduction System Software -features Types
Inroduction System Software -features TypesInroduction System Software -features Types
Inroduction System Software -features Types
 
2.dfa.pdf
2.dfa.pdf2.dfa.pdf
2.dfa.pdf
 
1.AutomataU1.pdf
1.AutomataU1.pdf1.AutomataU1.pdf
1.AutomataU1.pdf
 
Pointer.pptx
Pointer.pptxPointer.pptx
Pointer.pptx
 

Recently uploaded

Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
ArianaBusciglio
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
MERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDFMERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDF
scholarhattraining
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Fresher’s Quiz 2023 at GMC Nizamabad.pptx
Fresher’s Quiz 2023 at GMC Nizamabad.pptxFresher’s Quiz 2023 at GMC Nizamabad.pptx
Fresher’s Quiz 2023 at GMC Nizamabad.pptx
SriSurya50
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Reflective and Evaluative Practice PowerPoint
Reflective and Evaluative Practice PowerPointReflective and Evaluative Practice PowerPoint
Reflective and Evaluative Practice PowerPoint
amberjdewit93
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
kitab khulasah nurul yaqin jilid 1 - 2.pptx
kitab khulasah nurul yaqin jilid 1 - 2.pptxkitab khulasah nurul yaqin jilid 1 - 2.pptx
kitab khulasah nurul yaqin jilid 1 - 2.pptx
datarid22
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 

Recently uploaded (20)

Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
MERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDFMERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDF
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Fresher’s Quiz 2023 at GMC Nizamabad.pptx
Fresher’s Quiz 2023 at GMC Nizamabad.pptxFresher’s Quiz 2023 at GMC Nizamabad.pptx
Fresher’s Quiz 2023 at GMC Nizamabad.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Reflective and Evaluative Practice PowerPoint
Reflective and Evaluative Practice PowerPointReflective and Evaluative Practice PowerPoint
Reflective and Evaluative Practice PowerPoint
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
kitab khulasah nurul yaqin jilid 1 - 2.pptx
kitab khulasah nurul yaqin jilid 1 - 2.pptxkitab khulasah nurul yaqin jilid 1 - 2.pptx
kitab khulasah nurul yaqin jilid 1 - 2.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 

Array.pptx

  • 1.
  • 2. C Array An array is defined as the collection of similar type of data items stored at contiguous memory locations. Arrays are the derived data type in C programming language which can store the primitive type of data such as int, char, double, float, etc
  • 3. Advantage of C Array 1) Code Optimization: Less code to the access the data. 2) Ease of traversing: By using the for loop, we can retrieve the elements of an array easily. 3) Ease of sorting: To sort the elements of the array, we need a few lines of code only. 4) Random Access: We can access any element randomly using the array. Disadvantage of C Array 1) Fixed Size: Whatever size, we define at the time of declaration of the array, we can't exceed the limit. So, it doesn't grow the size dynamically like LinkedList which we will learn later.
  • 4. Declaration of C Array data_type array_name[array_size]; Eg- int marks[5];
  • 5. Initialization of C Array marks[0]=80; marks[1]=60; marks[2]=70; marks[3]=85; marks[4]=75; int marks[5]={20,30,40,50,60};
  • 6. Program to declare & Initialize Array
  • 7.
  • 8. Program for character Array initialization & Declaration
  • 9.
  • 10. Program for addition of all array elements
  • 11. Program to find smallest array element
  • 12. Program for addition of all Odd array elements
  • 14. Single Dimentional Array Representation
  • 15.
  • 17. Two dimensional arrays •At times we need to store the data in form of tables or matrices. For this, we can use the two dimensional arrays. •This array is specified by using two subscripts where one subscript is denoted as the row and the other as the column. •It is also viewed as an array of arrays.
  • 18.
  • 19. 2- Dimentional Array Representation
  • 20. Declaration of a two-dimensional array data_type array_name [row_size] [column_size] ; The declaration of the rows and columns is compulsory for a two-dimensional array. We cannot replace the row size with the column size and the column size to row size. The proper sequence has to be maintained int score[3][2] ;
  • 21. Initialization of 2D array 1. int score [3][2] ={50, 60, 70, 95, 3, 36}; 2. int score [3][2] ={{50, 60} , {70,95} ,{3,36}}; 3. score[0][0] = 50; score [0][1] = 60; score[1][0] = 70 ; score [1][1] = 95; score[2][0] = 3; score [2][1] = 36;
  • 22.
  • 23. 2-D Array Declaration & Initialization
  • 24. 2-D Array Element modification
  • 25. Program for addition of all elements in 2-D Array
  • 26. Linear Search A linear search, also known as a sequential search, is a method of finding an element within a list. It checks each element of the list sequentially until a match is found or the whole list has been searched
  • 27. Program to search array element using Linear Search
  • 28. Passing array to function In C programming, you can pass an entire array to functions In C programming, you can pass an entire array to functions
  • 29. Passing array to function
  • 30. String A string in C is array of characters. The string can be defined as the one-dimensional array of characters terminated by a NULL ('0’). The string is used to manipulate text such as word or sentences. The termination character ('0') / NULL character: -The termination character ('0') is important in a string since it is only way to identify where the string ends.
  • 32. #include <stdio.h> #include <string.h> int main() { char a[20]="Program"; char b[20]={'P','r','o','g','r','a','m','0'}; printf("Length of string a = %d n",strlen(a)); printf("Length of string b = %d n",strlen(b)); return 0; } String Length (strlen)
  • 33. #include <stdio.h> #include <string.h> int main() { char str1[20] = "C programming"; char str2[20]; // copying str1 to str2 strcpy(str2, str1); puts(str2); // C programming return 0; } String Copy(strcpy)
  • 34. #include <string.h> int main() { char str1[100] = "Welcome to ", str2[] = "RIT"; // concatenates str1 and str2 // the resultant string is stored in str1. strcat(str1, str2); puts(str1); puts(str2); return 0; } String Concat (strcat)
  • 35. #include <string.h> int main() { char str1[100] = "c programming..."; printf("%s",strupr(str1)); } String Upper Case (strupr)
  • 36. #include <string.h> int main() { char str1[100] = "WELCOME TO RIT"; printf("%s",strlwr(str1)); } String Lower Case (strlwr)
  • 37. The strcmp() compares two strings character by character. If the strings are equal, the function retu otherwise returns 1. String Compare (strcmp) #include <stdio.h> #include <string.h> int main() { char str1[] = "abcd", str2[] = "abCd", str3[] = "abcd"; int result; // comparing strings str1 and str2 result = strcmp(str1, str2); printf("strcmp(str1, str2) = %dn", result); // comparing strings str1 and str3 result = strcmp(str1, str3); printf("strcmp(str1, str3) = %dn", result); return 0; }