Array and string

prashant chelani
prashant chelaniStudent at Dr.S.& S.S.Gandhi college of Engg. And Technology,Surat 612
Dr. S. & S.S. Gandhy Government College of
Engineering and Technology
SEM:- 1ST
SUBJECT:- COMPUTER PROGRAMMING AND UTILIZATION
TOPIC:- ARRAY AND STRING
STUDENT’S NAME:-
PRATIK B. PATEL
PRASHANT A. CHELANI
VIJAY D. VADHER
NIKHIL R. PATIL
ARRAY :-
 NEED OF ARRAY
 ARRAY CONCEPT
 DECLARATION OF ONE-
DIMENTIONAL ARRAY
 INITIALIZATION OF ONE-
DIMENTIONAL ARRAY
 MULTYDIMENSIONAL ARRAY
NEED OF ARRAY:
 It is very difficult to write a
program in ‘C’ which consisting
large data items like addition of
50 integers, marks of student in
University, etc.
 ‘C’ program provides a solution
called ‘ARRAY’.
 By using array, it is easy to
include large numbers of data
items.
ARRAY CONCEPT:-
 An array is a group of data items of
the same data type that share a
common name.
 An array should be of same datatype
and consists of integers or strings and
so on.
 An array is linear and homogeneous.
 An array stores the data elements in
sequential order.
 Homogeneous means all data items
are of same datatype.
 Elements of array are specifying a
subscript.
 A subscript is also called index.
 Subscipt is start from 0 and cannot
negative.
 There are two types of array.
 1). One-dimentional arrays(also called
vectors)
 2). Multi-dimentional arrays(also called
Matrix)
DECLARATION OF ONE-
DIMENTIONAL ARRAY:-
 Syntex: datatype arrayname[size]
 Where,
 datatype:- The type of the data stored in the
array
 Arrayname:- Name of the array
 Size:- Maximum number of elements an array
can hold
 Example:- int marks[10]
Mark[0] Mark[1] ………….. ………..... Mark[9]
INITIALIZATIONOF ONE-DIMENTIONAL
ARRAY
 Int mark[6]={3,7,8,4,5,6}
 Is also equel to
 Int mark[]={3,7,8,4,5,6}
 It will occupy in memory like,
 a[0] a[1] a[2] a[3] a[4] a[5]
 Char a[8]={‘L’,’E’,’A’,’R’,’N’,’’,’C’}

 a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7]
 When compiler sees a character array, it add a null
character.So, while declaring a character array, we
must allow one extra element space for null character.
3 7 8 4 5 6
‘L’ ‘E’ ‘A’ ‘R’ ‘N’ ‘’ ‘C’ ‘0’
MULTYDIMENSIONAL ARRAY
 If an array have more than one dimension, is called
multi-dimensional array.
 Two dimensional array have two subscript, three
dimensional array have three subscript.
 Declaration of two dimensional array:-
 Int a[2][3]
 It consist of two rows and three colomns.
 a[0][0] a[0][1] a[0][2] a[1][0] a[1][1] a[1][2]
1 2 3 4 5 6
PROGRAMOF SIMPLE ARRAY
SOURCE CODE OUTPUT
Program to reverse a array
SOURCE CODE OUTPUT
Strings
 INTRODUCTION
 INITIALIZING STRING VARIABLES
 READING AND DISPLAYING STRINGS
 STRING HANDLING FUNCTIONS
 PROGRAMS OF STRING
INTRODUCTION :-
 Strings are array of characters i.e. they are
characters arranged one after another in
memory. Thus, a character array is called
string.
 Each character within the string is stored
within one element of the array
successively.
 A string is always terminated by a null
character (i.e. slash zero 0).
 A string variable is declared as an
array of characters.
 Syntax:
char string_name[size];
 E.g. char name[20];
 When the compiler assigns a character
string to a character array, it
automatically supplies a null character
(‘0’) at the end of the string
Initializing String
Variables
 Strings are initialized in either of the following two forms:
char name[4]={‘R’,‘A’,‘M’, ‘0’};
char name[]={‘R’,‘A’,‘M’, ‘0’};
OR
char name[4]=“RAM”;
char name[]=“RAM”;
 When we initialize a character array by listing its
elements, the null terminator or the size of the array must
be provided explicitly.
R A M 0
name[0] name[1] name[2] name[3]
Reading and displaying Strings
 It can be done manually.
 Using printf() and scanf().
 Using gets() and puts().
Using printf() and scanf()
SOURCE CODE OUTPUT
Using gets() and puts()
SOURCE CODE OUTPUT
String handling functions
strcpy ( ) Copies str2 into str1
strlen ( ) Gives the length of str1
strcmp ( ) Returns 0 if str1 is same as
str2. Returns <0 if strl <
str2. Returns >0 if str1 > str2
strcmpi ( ) Same as strcmp() function. But,
this function negotiates case. “A”
and “a” are treated as same.
strdup ( ) Duplicates the string
strlwr ( ) Converts string to lowercase
strupr ( ) Converts string to uppercase
strrev ( ) Reverses the given string
Program to find string length using
function
SOURCE CODE OUTPUT
Program to Reverse string using function
SOURCE CODE OUTPUT
DIFFERECE BETWEEN ARRAY AND
STRING
ARRAY STRING
An array can hold any data type. String can hold only char data
An array size can not be A string size can be changed if it
is a char pointer
The last element of an array is an
element of the specific type.
The last character of a string is a
null – ‘0’ character.
The length of an array is to
specified in [] at the time of
declaration (except char[]).
The length of the string is the
number of characters + one (null
character).
Array and string
1 de 22

Recomendados

structure and union por
structure and unionstructure and union
structure and unionstudent
15.3K visualizações41 slides
Array in c por
Array in cArray in c
Array in cRavi Gelani
50.2K visualizações22 slides
Programming in c Arrays por
Programming in c ArraysProgramming in c Arrays
Programming in c Arraysjanani thirupathi
23.7K visualizações31 slides
Arrays and Strings por
Arrays and Strings Arrays and Strings
Arrays and Strings Dr.Subha Krishna
4.2K visualizações39 slides
Character Array and String por
Character Array and StringCharacter Array and String
Character Array and StringTasnima Hamid
933 visualizações27 slides
Introduction to Array ppt por
Introduction to Array pptIntroduction to Array ppt
Introduction to Array pptsandhya yadav
6.8K visualizações15 slides

Mais conteúdo relacionado

Mais procurados

Strings in c++ por
Strings in c++Strings in c++
Strings in c++Neeru Mittal
4.5K visualizações31 slides
Array Introduction One-dimensional array Multidimensional array por
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayimtiazalijoono
5.3K visualizações27 slides
Strings in C por
Strings in CStrings in C
Strings in CKamal Acharya
24K visualizações22 slides
Constants in C Programming por
Constants in C ProgrammingConstants in C Programming
Constants in C Programmingprogramming9
6.3K visualizações11 slides
Arrays in Java por
Arrays in JavaArrays in Java
Arrays in JavaNaz Abdalla
1.9K visualizações22 slides
Pointer in c por
Pointer in cPointer in c
Pointer in clavanya marichamy
15.2K visualizações14 slides

Mais procurados(20)

Strings in c++ por Neeru Mittal
Strings in c++Strings in c++
Strings in c++
Neeru Mittal4.5K visualizações
Array Introduction One-dimensional array Multidimensional array por imtiazalijoono
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono5.3K visualizações
Strings in C por Kamal Acharya
Strings in CStrings in C
Strings in C
Kamal Acharya24K visualizações
Constants in C Programming por programming9
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
programming96.3K visualizações
Arrays in Java por Naz Abdalla
Arrays in JavaArrays in Java
Arrays in Java
Naz Abdalla1.9K visualizações
Pointer in c por lavanya marichamy
Pointer in cPointer in c
Pointer in c
lavanya marichamy15.2K visualizações
Strings in c por vampugani
Strings in cStrings in c
Strings in c
vampugani2.4K visualizações
Intoduction to structure por Utsav276
Intoduction to structureIntoduction to structure
Intoduction to structure
Utsav276512 visualizações
Array in c++ por Mahesha Mano
Array in c++Array in c++
Array in c++
Mahesha Mano13.6K visualizações
FUNCTIONS IN c++ PPT por 03062679929
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
0306267992925.3K visualizações
Chapter 05 classes and objects por praveenjigajinni
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
praveenjigajinni2.8K visualizações
Tokens in C++ por Mahender Boda
Tokens in C++Tokens in C++
Tokens in C++
Mahender Boda6.5K visualizações
Structure in C por Kamal Acharya
Structure in CStructure in C
Structure in C
Kamal Acharya35.3K visualizações
Presentation on array por topu93
Presentation on array Presentation on array
Presentation on array
topu936.7K visualizações
Strings IN C por yndaravind
Strings IN CStrings IN C
Strings IN C
yndaravind254 visualizações
String c por thirumalaikumar3
String cString c
String c
thirumalaikumar38.5K visualizações
Two dimensional array por Rajendran
Two dimensional arrayTwo dimensional array
Two dimensional array
Rajendran 5.1K visualizações
Array in-c por Samsil Arefin
Array in-cArray in-c
Array in-c
Samsil Arefin471 visualizações
Data types in C language por kashyap399
Data types in C languageData types in C language
Data types in C language
kashyap3991.2K visualizações
Structures in c language por tanmaymodi4
Structures in c languageStructures in c language
Structures in c language
tanmaymodi44.2K visualizações

Destaque

Bitwise operators por
Bitwise operatorsBitwise operators
Bitwise operatorsPuneet Rajput
3.2K visualizações7 slides
Parm por
ParmParm
Parmparmsidhu
403 visualizações33 slides
principle of oop’s in cpp por
principle of oop’s in cppprinciple of oop’s in cpp
principle of oop’s in cppgourav kottawar
1.9K visualizações38 slides
Lecture 11 bitwise_operator por
Lecture 11 bitwise_operatorLecture 11 bitwise_operator
Lecture 11 bitwise_operatoreShikshak
897 visualizações12 slides
Graphics in C programming por
Graphics in C programmingGraphics in C programming
Graphics in C programmingKamal Acharya
6.2K visualizações21 slides
Inheritance, friend function, virtual function, polymorphism por
Inheritance, friend function, virtual function, polymorphismInheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphismJawad Khan
1.1K visualizações21 slides

Destaque(20)

Bitwise operators por Puneet Rajput
Bitwise operatorsBitwise operators
Bitwise operators
Puneet Rajput3.2K visualizações
Parm por parmsidhu
ParmParm
Parm
parmsidhu403 visualizações
principle of oop’s in cpp por gourav kottawar
principle of oop’s in cppprinciple of oop’s in cpp
principle of oop’s in cpp
gourav kottawar1.9K visualizações
Lecture 11 bitwise_operator por eShikshak
Lecture 11 bitwise_operatorLecture 11 bitwise_operator
Lecture 11 bitwise_operator
eShikshak897 visualizações
Graphics in C programming por Kamal Acharya
Graphics in C programmingGraphics in C programming
Graphics in C programming
Kamal Acharya6.2K visualizações
Inheritance, friend function, virtual function, polymorphism por Jawad Khan
Inheritance, friend function, virtual function, polymorphismInheritance, friend function, virtual function, polymorphism
Inheritance, friend function, virtual function, polymorphism
Jawad Khan1.1K visualizações
Structures por archikabhatia
StructuresStructures
Structures
archikabhatia3.5K visualizações
Lec 42.43 - virtual.functions por Princess Sam
Lec 42.43 - virtual.functionsLec 42.43 - virtual.functions
Lec 42.43 - virtual.functions
Princess Sam4.3K visualizações
15 bitwise operators por Ravindra Rathore
15 bitwise operators15 bitwise operators
15 bitwise operators
Ravindra Rathore8K visualizações
C++ Language por Syed Zaid Irshad
C++ LanguageC++ Language
C++ Language
Syed Zaid Irshad1.3K visualizações
Virtual function por harman kaur
Virtual functionVirtual function
Virtual function
harman kaur3.4K visualizações
Functions in C por Shobhit Upadhyay
Functions in CFunctions in C
Functions in C
Shobhit Upadhyay4.1K visualizações
Embedded c programming22 for fdp por Pradeep Kumar TS
Embedded c programming22 for fdpEmbedded c programming22 for fdp
Embedded c programming22 for fdp
Pradeep Kumar TS1.7K visualizações
Function in c por Raj Tandukar
Function in cFunction in c
Function in c
Raj Tandukar6.8K visualizações
operator overloading & type conversion in cpp over view || c++ por gourav kottawar
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
gourav kottawar3.2K visualizações
Function in C por Dr. Abhineet Anand
Function in CFunction in C
Function in C
Dr. Abhineet Anand10.2K visualizações
C Pointers por omukhtar
C PointersC Pointers
C Pointers
omukhtar28K visualizações

Similar a Array and string

C Programming Unit-3 por
C Programming Unit-3C Programming Unit-3
C Programming Unit-3Vikram Nandini
336 visualizações23 slides
C UNIT-3 PREPARED BY M V B REDDY por
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
388 visualizações54 slides
Unit ii data structure-converted por
Unit  ii data structure-convertedUnit  ii data structure-converted
Unit ii data structure-convertedShri Shankaracharya College, Bhilai,Junwani
70 visualizações25 slides
Array assignment por
Array assignmentArray assignment
Array assignmentAhmad Kamal
1.3K visualizações25 slides
Arrays and library functions por
Arrays and library functionsArrays and library functions
Arrays and library functionsSwarup Boro
1.5K visualizações13 slides
Introduction to Arrays in C por
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in CThesis Scientist Private Limited
266 visualizações5 slides

Similar a Array and string(20)

C Programming Unit-3 por Vikram Nandini
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
Vikram Nandini336 visualizações
C UNIT-3 PREPARED BY M V B REDDY por Rajeshkumar 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
Rajeshkumar Reddy388 visualizações
Array assignment por Ahmad Kamal
Array assignmentArray assignment
Array assignment
Ahmad Kamal1.3K visualizações
Arrays and library functions por Swarup Boro
Arrays and library functionsArrays and library functions
Arrays and library functions
Swarup Boro1.5K visualizações
3.ArraysandPointers.pptx por FolkAdonis
3.ArraysandPointers.pptx3.ArraysandPointers.pptx
3.ArraysandPointers.pptx
FolkAdonis1 visão
Arrays in C language por Shubham Sharma
Arrays in C languageArrays in C language
Arrays in C language
Shubham Sharma7.5K visualizações
Module 4- Arrays and Strings por nikshaikh786
Module 4- Arrays and StringsModule 4- Arrays and Strings
Module 4- Arrays and Strings
nikshaikh786149 visualizações
Arrays and library functions por Swarup Kumar Boro
Arrays and library functionsArrays and library functions
Arrays and library functions
Swarup Kumar Boro598 visualizações
Unit 2 por Sowri Rajan
Unit 2Unit 2
Unit 2
Sowri Rajan18 visualizações
C programming session 04 por Dushmanta Nath
C programming session 04C programming session 04
C programming session 04
Dushmanta Nath1.4K visualizações
02 arrays por Rajan Gautam
02 arrays02 arrays
02 arrays
Rajan Gautam123 visualizações
Unitii classnotes por Sowri Rajan
Unitii classnotesUnitii classnotes
Unitii classnotes
Sowri Rajan11 visualizações
Arrays-Computer programming por nmahi96
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
nmahi9671 visualizações
Ocs752 unit 3 por mgrameshmail
Ocs752   unit 3Ocs752   unit 3
Ocs752 unit 3
mgrameshmail365 visualizações
Module 3 - Regular Expressions, Dictionaries.pdf por GaneshRaghu4
Module 3 - Regular  Expressions,  Dictionaries.pdfModule 3 - Regular  Expressions,  Dictionaries.pdf
Module 3 - Regular Expressions, Dictionaries.pdf
GaneshRaghu42 visualizações
C Programming : Arrays por Gagan Deep
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
Gagan Deep9K visualizações
Week6_P_String.pptx por OluwafolakeOjo
Week6_P_String.pptxWeek6_P_String.pptx
Week6_P_String.pptx
OluwafolakeOjo3 visualizações

Mais de prashant chelani

Traffic engineering topic 19 street lighting por
Traffic engineering topic  19 street lightingTraffic engineering topic  19 street lighting
Traffic engineering topic 19 street lightingprashant chelani
2.1K visualizações25 slides
Dm = Landslide and Avalanche por
Dm = Landslide and AvalancheDm = Landslide and Avalanche
Dm = Landslide and Avalancheprashant chelani
1.5K visualizações21 slides
Gate civil engineering por
Gate civil engineeringGate civil engineering
Gate civil engineeringprashant chelani
528 visualizações12 slides
Calculus multiple integral por
Calculus multiple integralCalculus multiple integral
Calculus multiple integralprashant chelani
298 visualizações21 slides
TYPES AND INFORMATION STONES por
TYPES AND INFORMATION STONESTYPES AND INFORMATION STONES
TYPES AND INFORMATION STONESprashant chelani
1.5K visualizações52 slides
Earth magnetic field por
Earth magnetic fieldEarth magnetic field
Earth magnetic fieldprashant chelani
6K visualizações18 slides

Mais de prashant chelani(8)

Traffic engineering topic 19 street lighting por prashant chelani
Traffic engineering topic  19 street lightingTraffic engineering topic  19 street lighting
Traffic engineering topic 19 street lighting
prashant chelani2.1K visualizações
Dm = Landslide and Avalanche por prashant chelani
Dm = Landslide and AvalancheDm = Landslide and Avalanche
Dm = Landslide and Avalanche
prashant chelani1.5K visualizações
Gate civil engineering por prashant chelani
Gate civil engineeringGate civil engineering
Gate civil engineering
prashant chelani528 visualizações
Calculus multiple integral por prashant chelani
Calculus multiple integralCalculus multiple integral
Calculus multiple integral
prashant chelani298 visualizações
TYPES AND INFORMATION STONES por prashant chelani
TYPES AND INFORMATION STONESTYPES AND INFORMATION STONES
TYPES AND INFORMATION STONES
prashant chelani1.5K visualizações
Earth magnetic field por prashant chelani
Earth magnetic fieldEarth magnetic field
Earth magnetic field
prashant chelani6K visualizações
Smartcity por prashant chelani
SmartcitySmartcity
Smartcity
prashant chelani157 visualizações
Finding value of pie and pythagorus and cryptography por prashant chelani
Finding value of pie and pythagorus and cryptographyFinding value of pie and pythagorus and cryptography
Finding value of pie and pythagorus and cryptography
prashant chelani386 visualizações

Último

REPRESENTATION - GAUNTLET.pptx por
REPRESENTATION - GAUNTLET.pptxREPRESENTATION - GAUNTLET.pptx
REPRESENTATION - GAUNTLET.pptxiammrhaywood
100 visualizações26 slides
Community-led Open Access Publishing webinar.pptx por
Community-led Open Access Publishing webinar.pptxCommunity-led Open Access Publishing webinar.pptx
Community-led Open Access Publishing webinar.pptxJisc
93 visualizações9 slides
The basics - information, data, technology and systems.pdf por
The basics - information, data, technology and systems.pdfThe basics - information, data, technology and systems.pdf
The basics - information, data, technology and systems.pdfJonathanCovena1
115 visualizações1 slide
231112 (WR) v1 ChatGPT OEB 2023.pdf por
231112 (WR) v1  ChatGPT OEB 2023.pdf231112 (WR) v1  ChatGPT OEB 2023.pdf
231112 (WR) v1 ChatGPT OEB 2023.pdfWilfredRubens.com
157 visualizações21 slides
ACTIVITY BOOK key water sports.pptx por
ACTIVITY BOOK key water sports.pptxACTIVITY BOOK key water sports.pptx
ACTIVITY BOOK key water sports.pptxMar Caston Palacio
605 visualizações4 slides
Gopal Chakraborty Memorial Quiz 2.0 Prelims.pptx por
Gopal Chakraborty Memorial Quiz 2.0 Prelims.pptxGopal Chakraborty Memorial Quiz 2.0 Prelims.pptx
Gopal Chakraborty Memorial Quiz 2.0 Prelims.pptxDebapriya Chakraborty
655 visualizações81 slides

Último(20)

REPRESENTATION - GAUNTLET.pptx por iammrhaywood
REPRESENTATION - GAUNTLET.pptxREPRESENTATION - GAUNTLET.pptx
REPRESENTATION - GAUNTLET.pptx
iammrhaywood100 visualizações
Community-led Open Access Publishing webinar.pptx por Jisc
Community-led Open Access Publishing webinar.pptxCommunity-led Open Access Publishing webinar.pptx
Community-led Open Access Publishing webinar.pptx
Jisc93 visualizações
The basics - information, data, technology and systems.pdf por JonathanCovena1
The basics - information, data, technology and systems.pdfThe basics - information, data, technology and systems.pdf
The basics - information, data, technology and systems.pdf
JonathanCovena1115 visualizações
231112 (WR) v1 ChatGPT OEB 2023.pdf por WilfredRubens.com
231112 (WR) v1  ChatGPT OEB 2023.pdf231112 (WR) v1  ChatGPT OEB 2023.pdf
231112 (WR) v1 ChatGPT OEB 2023.pdf
WilfredRubens.com157 visualizações
ACTIVITY BOOK key water sports.pptx por Mar Caston Palacio
ACTIVITY BOOK key water sports.pptxACTIVITY BOOK key water sports.pptx
ACTIVITY BOOK key water sports.pptx
Mar Caston Palacio605 visualizações
Gopal Chakraborty Memorial Quiz 2.0 Prelims.pptx por Debapriya Chakraborty
Gopal Chakraborty Memorial Quiz 2.0 Prelims.pptxGopal Chakraborty Memorial Quiz 2.0 Prelims.pptx
Gopal Chakraborty Memorial Quiz 2.0 Prelims.pptx
Debapriya Chakraborty655 visualizações
ICS3211_lecture 08_2023.pdf por Vanessa Camilleri
ICS3211_lecture 08_2023.pdfICS3211_lecture 08_2023.pdf
ICS3211_lecture 08_2023.pdf
Vanessa Camilleri149 visualizações
The Accursed House by Émile Gaboriau por DivyaSheta
The Accursed House  by Émile GaboriauThe Accursed House  by Émile Gaboriau
The Accursed House by Émile Gaboriau
DivyaSheta201 visualizações
11.28.23 Social Capital and Social Exclusion.pptx por mary850239
11.28.23 Social Capital and Social Exclusion.pptx11.28.23 Social Capital and Social Exclusion.pptx
11.28.23 Social Capital and Social Exclusion.pptx
mary850239298 visualizações
JiscOAWeek_LAIR_slides_October2023.pptx por Jisc
JiscOAWeek_LAIR_slides_October2023.pptxJiscOAWeek_LAIR_slides_October2023.pptx
JiscOAWeek_LAIR_slides_October2023.pptx
Jisc96 visualizações
Education and Diversity.pptx por DrHafizKosar
Education and Diversity.pptxEducation and Diversity.pptx
Education and Diversity.pptx
DrHafizKosar173 visualizações
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively por PECB
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks EffectivelyISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
PECB 585 visualizações
CWP_23995_2013_17_11_2023_FINAL_ORDER.pdf por SukhwinderSingh895865
CWP_23995_2013_17_11_2023_FINAL_ORDER.pdfCWP_23995_2013_17_11_2023_FINAL_ORDER.pdf
CWP_23995_2013_17_11_2023_FINAL_ORDER.pdf
SukhwinderSingh895865527 visualizações
AUDIENCE - BANDURA.pptx por iammrhaywood
AUDIENCE - BANDURA.pptxAUDIENCE - BANDURA.pptx
AUDIENCE - BANDURA.pptx
iammrhaywood84 visualizações
Class 10 English notes 23-24.pptx por TARIQ KHAN
Class 10 English notes 23-24.pptxClass 10 English notes 23-24.pptx
Class 10 English notes 23-24.pptx
TARIQ KHAN131 visualizações
Use of Probiotics in Aquaculture.pptx por AKSHAY MANDAL
Use of Probiotics in Aquaculture.pptxUse of Probiotics in Aquaculture.pptx
Use of Probiotics in Aquaculture.pptx
AKSHAY MANDAL100 visualizações
Psychology KS4 por WestHatch
Psychology KS4Psychology KS4
Psychology KS4
WestHatch84 visualizações
Class 10 English lesson plans por TARIQ KHAN
Class 10 English  lesson plansClass 10 English  lesson plans
Class 10 English lesson plans
TARIQ KHAN288 visualizações
ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1} por DR .PALLAVI PATHANIA
ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}
ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}
DR .PALLAVI PATHANIA249 visualizações

Array and string

  • 1. Dr. S. & S.S. Gandhy Government College of Engineering and Technology SEM:- 1ST SUBJECT:- COMPUTER PROGRAMMING AND UTILIZATION TOPIC:- ARRAY AND STRING STUDENT’S NAME:- PRATIK B. PATEL PRASHANT A. CHELANI VIJAY D. VADHER NIKHIL R. PATIL
  • 2. ARRAY :-  NEED OF ARRAY  ARRAY CONCEPT  DECLARATION OF ONE- DIMENTIONAL ARRAY  INITIALIZATION OF ONE- DIMENTIONAL ARRAY  MULTYDIMENSIONAL ARRAY
  • 3. NEED OF ARRAY:  It is very difficult to write a program in ‘C’ which consisting large data items like addition of 50 integers, marks of student in University, etc.  ‘C’ program provides a solution called ‘ARRAY’.  By using array, it is easy to include large numbers of data items.
  • 4. ARRAY CONCEPT:-  An array is a group of data items of the same data type that share a common name.  An array should be of same datatype and consists of integers or strings and so on.  An array is linear and homogeneous.  An array stores the data elements in sequential order.  Homogeneous means all data items are of same datatype.
  • 5.  Elements of array are specifying a subscript.  A subscript is also called index.  Subscipt is start from 0 and cannot negative.  There are two types of array.  1). One-dimentional arrays(also called vectors)  2). Multi-dimentional arrays(also called Matrix)
  • 6. DECLARATION OF ONE- DIMENTIONAL ARRAY:-  Syntex: datatype arrayname[size]  Where,  datatype:- The type of the data stored in the array  Arrayname:- Name of the array  Size:- Maximum number of elements an array can hold  Example:- int marks[10] Mark[0] Mark[1] ………….. ………..... Mark[9]
  • 7. INITIALIZATIONOF ONE-DIMENTIONAL ARRAY  Int mark[6]={3,7,8,4,5,6}  Is also equel to  Int mark[]={3,7,8,4,5,6}  It will occupy in memory like,  a[0] a[1] a[2] a[3] a[4] a[5]  Char a[8]={‘L’,’E’,’A’,’R’,’N’,’’,’C’}   a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7]  When compiler sees a character array, it add a null character.So, while declaring a character array, we must allow one extra element space for null character. 3 7 8 4 5 6 ‘L’ ‘E’ ‘A’ ‘R’ ‘N’ ‘’ ‘C’ ‘0’
  • 8. MULTYDIMENSIONAL ARRAY  If an array have more than one dimension, is called multi-dimensional array.  Two dimensional array have two subscript, three dimensional array have three subscript.  Declaration of two dimensional array:-  Int a[2][3]  It consist of two rows and three colomns.  a[0][0] a[0][1] a[0][2] a[1][0] a[1][1] a[1][2] 1 2 3 4 5 6
  • 10. Program to reverse a array SOURCE CODE OUTPUT
  • 11. Strings  INTRODUCTION  INITIALIZING STRING VARIABLES  READING AND DISPLAYING STRINGS  STRING HANDLING FUNCTIONS  PROGRAMS OF STRING
  • 12. INTRODUCTION :-  Strings are array of characters i.e. they are characters arranged one after another in memory. Thus, a character array is called string.  Each character within the string is stored within one element of the array successively.  A string is always terminated by a null character (i.e. slash zero 0).
  • 13.  A string variable is declared as an array of characters.  Syntax: char string_name[size];  E.g. char name[20];  When the compiler assigns a character string to a character array, it automatically supplies a null character (‘0’) at the end of the string
  • 14. Initializing String Variables  Strings are initialized in either of the following two forms: char name[4]={‘R’,‘A’,‘M’, ‘0’}; char name[]={‘R’,‘A’,‘M’, ‘0’}; OR char name[4]=“RAM”; char name[]=“RAM”;  When we initialize a character array by listing its elements, the null terminator or the size of the array must be provided explicitly. R A M 0 name[0] name[1] name[2] name[3]
  • 15. Reading and displaying Strings  It can be done manually.  Using printf() and scanf().  Using gets() and puts().
  • 16. Using printf() and scanf() SOURCE CODE OUTPUT
  • 17. Using gets() and puts() SOURCE CODE OUTPUT
  • 18. String handling functions strcpy ( ) Copies str2 into str1 strlen ( ) Gives the length of str1 strcmp ( ) Returns 0 if str1 is same as str2. Returns <0 if strl < str2. Returns >0 if str1 > str2 strcmpi ( ) Same as strcmp() function. But, this function negotiates case. “A” and “a” are treated as same. strdup ( ) Duplicates the string strlwr ( ) Converts string to lowercase strupr ( ) Converts string to uppercase strrev ( ) Reverses the given string
  • 19. Program to find string length using function SOURCE CODE OUTPUT
  • 20. Program to Reverse string using function SOURCE CODE OUTPUT
  • 21. DIFFERECE BETWEEN ARRAY AND STRING ARRAY STRING An array can hold any data type. String can hold only char data An array size can not be A string size can be changed if it is a char pointer The last element of an array is an element of the specific type. The last character of a string is a null – ‘0’ character. The length of an array is to specified in [] at the time of declaration (except char[]). The length of the string is the number of characters + one (null character).