SlideShare a Scribd company logo
INTRODUCTION TO ARRAY AND STRING
Team Members:
Sajid Anowar
ID: 191-35-390
Muntasir Muhit
ID: 191-35-399
Array
CONTENT:
• Array
• Types of Array
Array
An array is a collection of one or more values of the
same type. Each value is called an element of
the array. The elements of the array share the same
variable name but each element has its own unique
index number (also known as a subscript). An
array can be of any type:
For example: int , float , char etc.
Syntax
data-type name[size1][size2]………[sizen];
Example: int a[6];
Array
Advantage of Array
• Huge amount of data can be stored under single variable name.
• Searching of data item is faster.
• 2 dimension arrays are used to represent the matrices.
• It is helpful in implementing other data structure like linked list,
queue, stack.
Types of Array
One Dimensional Array
A one-dimensional
array (or single dimension
array) is a type of
linear array. Accessing its
elements involves
a single subscript which can
either represent a row or
column index.
SYNTAX: data-type name[index];
EXAMPLE: int num[10];
Initialization
• int num[6]={2,4,6,7,8,12};
• Individual elements can also be initialize as:
num[0]=2;
num[1]=4;
num[2]=6;
num[3]=7;
num[4]=8;
num[5]=12;
Reading Data from User
• for loop is used to read data from the user.
for(i=0;i<10;i++)
{
scanf(“%d”,&num[i]);
}
MULTI DIMENTIONAL ARRAY
The two dimensional (2D) array
in C programming is also
known as matrix. A matrix
can be represented as a
table of rows and columns
SYNTAX: data-type name[row-size][column-size];
EXAMPLE: int a[3][4];
Initialization
• int odd[3][2]={1,3,5,7,9,11};
Individual element can also be assigned as:
Odd[0][0]=1;
Odd[0][1]=3;
Odd[1][0]=5;
Odd[1][1]=7;
Odd[2][0]=9;
Odd[2][1]=11;
Reading Data from User
• Nested for Loop is used.
for(i=0;i<3;i++)
{
for(j=0;j<2;j++)
scanf(“%d”,&odd[i] [j]);
}
STRING
WHAT IS STRING ?
A group of characters A string constant is a one-
dimensional array
of characters terminated by a null ( ‘0’ ).
declaration of Character:
• char mychar;
declaration of String:
• char myString[10];
The characters after the null character are ignored.
WHAT IS NULL char ?
• Null ‘0’ is a terminator which terminates the string in an array
WHY NULL char ?
When declaring a string don’t forget to leave a space for the null
character which is also known as the string terminator character
only way the functions that work with a string can know where the
string ends.
INPUT FUNCTION
• Input Function :
The scanf() Function
• header file stdio.h
• Syntax:
• char mystring[100];
• scanf(“%s”, mystring);
The name of a string is a pointer constant to the first character in the character
array.
Problem:
terminates its input on the first white space it finds.
white space includes blanks, tabs, carriage returns(CR), form feeds & new line.
EXAMPLE
PROGRAM OUTPUT
INPUT FUNCTION
The gets() Function:
Header file stdio.h
takes a string from standard input and assigns it to a character array.
It replaces the n with 0.
Syntax:
• char mystring[100];
• gets(myString);
• fgets() it keeps the n and includes it as part of the string.
EXAMPLE
PROGRAM OUTPUT
OUTPUT FUNCTION
The printf () function
header file: stdio.h
The puts() function
header file: stdio.h
PROGRAM
OUTPUT
STRING OPERATION(string.h)
Four main library function which is define in
• string.h header file
• strcpy() - copy one string into another
• strcat() - append one string onto the right side of
• the other
• strcmp() – compare alphabetic order of two
• strings
• strlen() – return the length of a string
Strcpy()
PROGRAM OUTPUT
strcat()
PROGRAM OUTPUT
Strcmp()
PROGRAM OUTPUT
Strlen()
PROGRAM OUTPUT
MORE FUNCTIONS
• strlwr() : converts a string to lowercase
• Strupr() : converts a string to uppercase
• Strncat() : Appends first n characters of a string at the end of
another
• Strncmp() :Compares first n characters of two strings
• Strcmpi():Compares two strings without regard to case ("i" denotes
that this function ignores Case)
• [Note: There are more library functions…..]
EXAMPLE
PROGRAM OUTPUT
Introduction to array and string

More Related Content

What's hot (20)

Strings in c
Strings in cStrings in c
Strings in c
vampugani
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
yndaravind
 
C programming - String
C programming - StringC programming - String
C programming - String
Achyut Devkota
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
Tasnima Hamid
 
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
 
Pointers in C
Pointers in CPointers in C
Pointers in C
Monishkanungo
 
String C Programming
String C ProgrammingString C Programming
String C Programming
Prionto Abdullah
 
Python-Tuples
Python-TuplesPython-Tuples
Python-Tuples
Krishna Nanda
 
Array in c
Array in cArray in c
Array in c
Ravi Gelani
 
structure and union
structure and unionstructure and union
structure and union
student
 
Member Function in C++
Member Function in C++ Member Function in C++
Member Function in C++
NikitaKaur10
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
ManishPrajapati78
 
Array and string
Array and stringArray and string
Array and string
prashant chelani
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
sai tarlekar
 
C string
C stringC string
C string
University of Potsdam
 
Python list
Python listPython list
Python list
ArchanaBhumkar
 
Pointers in C
Pointers in CPointers in C
Pointers in C
Kamal Acharya
 
Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
C Token’s
C Token’sC Token’s
C Token’s
Tarun Sharma
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
Appili Vamsi Krishna
 

Similar to Introduction to array and string (20)

MODUL new hlgjg thaybkhvnghgpv7E_02.pptx
MODUL new hlgjg thaybkhvnghgpv7E_02.pptxMODUL new hlgjg thaybkhvnghgpv7E_02.pptx
MODUL new hlgjg thaybkhvnghgpv7E_02.pptx
lomic31750
 
Array.pptx
Array.pptxArray.pptx
Array.pptx
SwapnaliPawar27
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
Vikram Nandini
 
[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++
Muhammad Hammad Waseem
 
ARRAY's in C Programming Language PPTX.
ARRAY's in C  Programming Language PPTX.ARRAY's in C  Programming Language PPTX.
ARRAY's in C Programming Language PPTX.
MSridhar18
 
Arrays
ArraysArrays
Arrays
Chukka Nikhil Chakravarthy
 
Unitii classnotes
Unitii classnotesUnitii classnotes
Unitii classnotes
Sowri Rajan
 
14 strings
14 strings14 strings
14 strings
Rohit Shrivastava
 
Diploma ii cfpc u-4 function, storage class and array and strings
Diploma ii  cfpc u-4 function, storage class and array and stringsDiploma ii  cfpc u-4 function, storage class and array and strings
Diploma ii cfpc u-4 function, storage class and array and strings
Rai University
 
Array , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptxArray , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptx
MrNikhilMohanShinde
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
Arrays & Strings.pptx
Arrays & Strings.pptxArrays & Strings.pptx
Arrays & Strings.pptx
AnkurRajSingh2
 
Mcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsMcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and strings
Rai University
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
Sowmya Jyothi
 
Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsBsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and strings
Rai University
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and strings
Rai University
 
Btech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsBtech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and strings
Rai University
 
Functions torage class and array and strings-
Functions torage class and array and strings-Functions torage class and array and strings-
Functions torage class and array and strings-
aneebkmct
 
Strings
StringsStrings
Strings
Mitali Chugh
 
Cfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPT
Cfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPTCfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPT
Cfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPT
JITENDER773791
 
MODUL new hlgjg thaybkhvnghgpv7E_02.pptx
MODUL new hlgjg thaybkhvnghgpv7E_02.pptxMODUL new hlgjg thaybkhvnghgpv7E_02.pptx
MODUL new hlgjg thaybkhvnghgpv7E_02.pptx
lomic31750
 
ARRAY's in C Programming Language PPTX.
ARRAY's in C  Programming Language PPTX.ARRAY's in C  Programming Language PPTX.
ARRAY's in C Programming Language PPTX.
MSridhar18
 
Unitii classnotes
Unitii classnotesUnitii classnotes
Unitii classnotes
Sowri Rajan
 
Diploma ii cfpc u-4 function, storage class and array and strings
Diploma ii  cfpc u-4 function, storage class and array and stringsDiploma ii  cfpc u-4 function, storage class and array and strings
Diploma ii cfpc u-4 function, storage class and array and strings
Rai University
 
Array , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptxArray , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptx
MrNikhilMohanShinde
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
Mcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsMcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and strings
Rai University
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
Sowmya Jyothi
 
Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsBsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and strings
Rai University
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and strings
Rai University
 
Btech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsBtech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and strings
Rai University
 
Functions torage class and array and strings-
Functions torage class and array and strings-Functions torage class and array and strings-
Functions torage class and array and strings-
aneebkmct
 
Cfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPT
Cfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPTCfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPT
Cfbcgdhfghdfhghggfhghghgfhgfhgfhhapter11.PPT
JITENDER773791
 
Ad

More from MuntasirMuhit (6)

Presentation on Airpollution Modeling
Presentation on Airpollution ModelingPresentation on Airpollution Modeling
Presentation on Airpollution Modeling
MuntasirMuhit
 
Presentation on graphics processing unit (GPU)
Presentation on graphics processing unit (GPU)Presentation on graphics processing unit (GPU)
Presentation on graphics processing unit (GPU)
MuntasirMuhit
 
Presentation on Data Structure
Presentation on Data StructurePresentation on Data Structure
Presentation on Data Structure
MuntasirMuhit
 
Statistics in real life
Statistics in real lifeStatistics in real life
Statistics in real life
MuntasirMuhit
 
Discrete mathematics for real world applications
Discrete mathematics for real world applicationsDiscrete mathematics for real world applications
Discrete mathematics for real world applications
MuntasirMuhit
 
Programming languages
Programming languagesProgramming languages
Programming languages
MuntasirMuhit
 
Presentation on Airpollution Modeling
Presentation on Airpollution ModelingPresentation on Airpollution Modeling
Presentation on Airpollution Modeling
MuntasirMuhit
 
Presentation on graphics processing unit (GPU)
Presentation on graphics processing unit (GPU)Presentation on graphics processing unit (GPU)
Presentation on graphics processing unit (GPU)
MuntasirMuhit
 
Presentation on Data Structure
Presentation on Data StructurePresentation on Data Structure
Presentation on Data Structure
MuntasirMuhit
 
Statistics in real life
Statistics in real lifeStatistics in real life
Statistics in real life
MuntasirMuhit
 
Discrete mathematics for real world applications
Discrete mathematics for real world applicationsDiscrete mathematics for real world applications
Discrete mathematics for real world applications
MuntasirMuhit
 
Programming languages
Programming languagesProgramming languages
Programming languages
MuntasirMuhit
 
Ad

Recently uploaded (20)

Pavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible PavementsPavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible Pavements
Sakthivel M
 
How Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdfHow Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdf
Mina Anis
 
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journeyRigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Yannis
 
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbbTree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
RATNANITINPATIL
 
SEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair KitSEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair Kit
projectultramechanix
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Artificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowyArtificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowy
dominikamizerska1
 
3. What is the principles of Teamwork_Module_V1.0.ppt
3. What is the principles of Teamwork_Module_V1.0.ppt3. What is the principles of Teamwork_Module_V1.0.ppt
3. What is the principles of Teamwork_Module_V1.0.ppt
engaash9
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
First Review PPT gfinal gyft ftu liu yrfut go
First Review PPT gfinal gyft  ftu liu yrfut goFirst Review PPT gfinal gyft  ftu liu yrfut go
First Review PPT gfinal gyft ftu liu yrfut go
Sowndarya6
 
chemistry investigatory project for class 12
chemistry investigatory project for class 12chemistry investigatory project for class 12
chemistry investigatory project for class 12
Susis10
 
Research_Sensitization_&_Innovative_Project_Development.pptx
Research_Sensitization_&_Innovative_Project_Development.pptxResearch_Sensitization_&_Innovative_Project_Development.pptx
Research_Sensitization_&_Innovative_Project_Development.pptx
niranjancse
 
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
SharinAbGhani1
 
Top Cite Articles- International Journal on Soft Computing, Artificial Intell...
Top Cite Articles- International Journal on Soft Computing, Artificial Intell...Top Cite Articles- International Journal on Soft Computing, Artificial Intell...
Top Cite Articles- International Journal on Soft Computing, Artificial Intell...
ijscai
 
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODSWIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
samueljackson3773
 
operationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagementoperationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagement
SNIGDHAAPPANABHOTLA
 
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptxWeek 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
dayananda54
 
David Boutry - Mentors Junior Developers
David Boutry - Mentors Junior DevelopersDavid Boutry - Mentors Junior Developers
David Boutry - Mentors Junior Developers
David Boutry
 
May 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information TechnologyMay 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
Pavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible PavementsPavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible Pavements
Sakthivel M
 
How Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdfHow Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdf
Mina Anis
 
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journeyRigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Yannis
 
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbbTree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
RATNANITINPATIL
 
SEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair KitSEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair Kit
projectultramechanix
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Artificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowyArtificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowy
dominikamizerska1
 
3. What is the principles of Teamwork_Module_V1.0.ppt
3. What is the principles of Teamwork_Module_V1.0.ppt3. What is the principles of Teamwork_Module_V1.0.ppt
3. What is the principles of Teamwork_Module_V1.0.ppt
engaash9
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
First Review PPT gfinal gyft ftu liu yrfut go
First Review PPT gfinal gyft  ftu liu yrfut goFirst Review PPT gfinal gyft  ftu liu yrfut go
First Review PPT gfinal gyft ftu liu yrfut go
Sowndarya6
 
chemistry investigatory project for class 12
chemistry investigatory project for class 12chemistry investigatory project for class 12
chemistry investigatory project for class 12
Susis10
 
Research_Sensitization_&_Innovative_Project_Development.pptx
Research_Sensitization_&_Innovative_Project_Development.pptxResearch_Sensitization_&_Innovative_Project_Development.pptx
Research_Sensitization_&_Innovative_Project_Development.pptx
niranjancse
 
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
SharinAbGhani1
 
Top Cite Articles- International Journal on Soft Computing, Artificial Intell...
Top Cite Articles- International Journal on Soft Computing, Artificial Intell...Top Cite Articles- International Journal on Soft Computing, Artificial Intell...
Top Cite Articles- International Journal on Soft Computing, Artificial Intell...
ijscai
 
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODSWIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
samueljackson3773
 
operationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagementoperationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagement
SNIGDHAAPPANABHOTLA
 
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptxWeek 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
dayananda54
 
David Boutry - Mentors Junior Developers
David Boutry - Mentors Junior DevelopersDavid Boutry - Mentors Junior Developers
David Boutry - Mentors Junior Developers
David Boutry
 
May 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information TechnologyMay 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information Technology
ijait
 

Introduction to array and string

  • 1. INTRODUCTION TO ARRAY AND STRING Team Members: Sajid Anowar ID: 191-35-390 Muntasir Muhit ID: 191-35-399
  • 3. Array An array is a collection of one or more values of the same type. Each value is called an element of the array. The elements of the array share the same variable name but each element has its own unique index number (also known as a subscript). An array can be of any type: For example: int , float , char etc.
  • 6. Advantage of Array • Huge amount of data can be stored under single variable name. • Searching of data item is faster. • 2 dimension arrays are used to represent the matrices. • It is helpful in implementing other data structure like linked list, queue, stack.
  • 8. One Dimensional Array A one-dimensional array (or single dimension array) is a type of linear array. Accessing its elements involves a single subscript which can either represent a row or column index. SYNTAX: data-type name[index]; EXAMPLE: int num[10];
  • 9. Initialization • int num[6]={2,4,6,7,8,12}; • Individual elements can also be initialize as: num[0]=2; num[1]=4; num[2]=6; num[3]=7; num[4]=8; num[5]=12;
  • 10. Reading Data from User • for loop is used to read data from the user. for(i=0;i<10;i++) { scanf(“%d”,&num[i]); }
  • 11. MULTI DIMENTIONAL ARRAY The two dimensional (2D) array in C programming is also known as matrix. A matrix can be represented as a table of rows and columns SYNTAX: data-type name[row-size][column-size]; EXAMPLE: int a[3][4];
  • 12. Initialization • int odd[3][2]={1,3,5,7,9,11}; Individual element can also be assigned as: Odd[0][0]=1; Odd[0][1]=3; Odd[1][0]=5; Odd[1][1]=7; Odd[2][0]=9; Odd[2][1]=11;
  • 13. Reading Data from User • Nested for Loop is used. for(i=0;i<3;i++) { for(j=0;j<2;j++) scanf(“%d”,&odd[i] [j]); }
  • 15. WHAT IS STRING ? A group of characters A string constant is a one- dimensional array of characters terminated by a null ( ‘0’ ). declaration of Character: • char mychar; declaration of String: • char myString[10]; The characters after the null character are ignored.
  • 16. WHAT IS NULL char ? • Null ‘0’ is a terminator which terminates the string in an array
  • 17. WHY NULL char ? When declaring a string don’t forget to leave a space for the null character which is also known as the string terminator character only way the functions that work with a string can know where the string ends.
  • 18. INPUT FUNCTION • Input Function : The scanf() Function • header file stdio.h • Syntax: • char mystring[100]; • scanf(“%s”, mystring); The name of a string is a pointer constant to the first character in the character array. Problem: terminates its input on the first white space it finds. white space includes blanks, tabs, carriage returns(CR), form feeds & new line.
  • 20. INPUT FUNCTION The gets() Function: Header file stdio.h takes a string from standard input and assigns it to a character array. It replaces the n with 0. Syntax: • char mystring[100]; • gets(myString); • fgets() it keeps the n and includes it as part of the string.
  • 22. OUTPUT FUNCTION The printf () function header file: stdio.h The puts() function header file: stdio.h PROGRAM OUTPUT
  • 23. STRING OPERATION(string.h) Four main library function which is define in • string.h header file • strcpy() - copy one string into another • strcat() - append one string onto the right side of • the other • strcmp() – compare alphabetic order of two • strings • strlen() – return the length of a string
  • 28. MORE FUNCTIONS • strlwr() : converts a string to lowercase • Strupr() : converts a string to uppercase • Strncat() : Appends first n characters of a string at the end of another • Strncmp() :Compares first n characters of two strings • Strcmpi():Compares two strings without regard to case ("i" denotes that this function ignores Case) • [Note: There are more library functions…..]