SlideShare a Scribd company logo
2
In above example, a is an array of type integer which has storage size of 3 elements.
One integer variable occupies 2 bytes. Hence the total size would be 3 * 2 = 6 bytes.
Memory Allocation :
P1: Program to display all elements of 1-D array.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20];
intn,i;
printf("n Enter the size of array :");
scanf("%d",&n);
printf("size of array is %d",n);
printf("n Enter Values to store in array one by one by pressing ENTER :");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("n The Values in array are..");
for(i=0;i<n;i++)
{
printf("n %d",a[i]);
}
getch();
}
Most read
6
P3:Program to find reverse of 1-D array
#include <stdio.h>
#include<conio.h>
void main()
{
int n, i, j, a[100], b[100];// a is original array and b is reversed array
printf("Enter the number of elements in arrayn");
Most read
13
Arrays can be categorized in following types
1. One dimensional array
2. Multi Dimensional array
These are described below.
The abstract model of string is implemented by defining a character array data type and
we need to include header file ‘string.h’, to hold all the relevant operations of string. The
string header file enables user to view complete string and perform various operation
on the string. E.g. we can call ‘strlen’ function to find length of string, ‘strcat’ to
concatenate two string, ‘strcpy’ to copy one string to another, ‘strrev’ to reverse the
string. The definitions of all these functions are stored in the header file ‘string.h’. So
string functions with the user provided data becomes the new data type in ‘C’.
Fig. 3.1 : String data type
To use the functions related to strings, user only need to include ‘string.h’ header file.
All the definitions details of these functions are keep hidden from the user, user can
directly use these function without knowing all the implementation details. This is known
as abstraction or hiding.
String Manipulation in C Language
Strings are also called as the array of character.
Most read
PPS
Unit – 4
Arrays
4.1 Array Declaration & Initialization
Array is defined as a collection of elements of same data type. Hence it is also called as
homogeneous variable. Total number of elements in array defines size of array. Position
of element in an array defines index or subscript of particular element. Array index
always starts with zero.
4.2 Bound Checking Arrays (1-D, 2-D)
1. One Dimensional Array:
The array which is used to represent and store data in a linear form is called as 'single or
one dimensional array.'
Syntax:
data-typearray_name[size];
Example 2:
int a[3] = {2, 3, 5};
charch[10] = "Data" ;
float x[3] = {2.5, 3.50,489.98} ;
Total Size of an array(in Bytes) can be calculated as follows:
total size(in bytes) = length of array * size of data type
In above example, a is an array of type integer which has storage size of 3 elements.
One integer variable occupies 2 bytes. Hence the total size would be 3 * 2 = 6 bytes.
Memory Allocation :
P1: Program to display all elements of 1-D array.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20];
intn,i;
printf("n Enter the size of array :");
scanf("%d",&n);
printf("size of array is %d",n);
printf("n Enter Values to store in array one by one by pressing ENTER :");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("n The Values in array are..");
for(i=0;i<n;i++)
{
printf("n %d",a[i]);
}
getch();
}
PPS 4.4ARRAYS  ARRAY DECLARATION & INITIALIZATION, BOUND CHECKING ARRAYS (1-D, 2-D), CHARACTER ARRAYS AND STRINGS.
P2: Program to copy 1-D array to another 1-D array
#include <stdio.h>
#include<conio.h>
void main()
{
int n, i, j, a[100], b[100];// a is original array and b is copied array
printf("Enter the number of elements in array an");
scanf("%d", &n);
printf("Enter the array elements in an");
for (i= 0; i< n ; i++)
scanf("%d", &a[i]);
/*
Copying elements from array a into array b */
for (i =0;i<n;i++)
b[i] = a[i];
/*
Printing copied array b
.
*/
printf("Elements of array b aren");
for (i = 0; i< n; i++)
printf("%dn", b[i]);
getch();
}
Output
P3:Program to find reverse of 1-D array
#include <stdio.h>
#include<conio.h>
void main()
{
int n, i, j, a[100], b[100];// a is original array and b is reversed array
printf("Enter the number of elements in arrayn");
scanf("%d", &n);
printf("Enter the array elementsn");
for (i= 0; i< n ; i++)
scanf("%d", &a[i]);
/*
* Copying elements into array b starting from end of array a
*/
for (i = n - 1, j = 0; i>= 0; i--, j++)
b[j] = a[i];
/*
Printing reversed array b
.
*/
printf("Reverse array isn");
for (i = 0; i< n; i++)
printf("%dn", a[i]);
getch();
}
Output:
PPS 4.4ARRAYS  ARRAY DECLARATION & INITIALIZATION, BOUND CHECKING ARRAYS (1-D, 2-D), CHARACTER ARRAYS AND STRINGS.
2. Multi Dimensional Array
1-D array has 1 row and multiple columns but multidimensional array has of multiple
rows and multiple columns.
Two Dimensional array:
Itis the simplest multidimensional array. They are also called as matrix.
Declaration:
data-typearray_name[no.of rows][no. of columns];
Total no of elements= No.of rows * No. of Columns
Example 3: inta[2][3]
This example illustrates two dimensional array a of 2 rows and 3 columns.
Total no of elements: 2*3=6
Total no of bytes occupied: 6( totalno.of elements )*2(Size of one element)=12
Initialization and Storage Representation:
In C, two dimensional arrays can be initialized in different number of ways. Specification
of no. of columns in 2 dimensional array is mandatory while no of rows is optional.
int a[2][3]={{1,3,0}, // Elements of 1st
row
{-1,5,9}}; // Elements of 2nd
row
OR
int a[][3]={{1,3,0}, // Elements of 1st
row
{-1,5,9}}; // Elements of 2nd
row
OR
int a[2][3]={1,3,0,-1,5,9};
Fig. 3 gives general storage representation of 2 dimensional array
Eg 4. int a[2][3]={1,3,0,-1,5,9}
Accessing Two-Dimensional Array Elements:
An element in 2-dimensional array is accessed by using the subscripts i.e. row index
and column index of the array. For example:
intval= A[1][2];
The above statement will access element from the 2nd
row and third column of the array
A i.e. element 9.
4.3 Character Arrays And Strings
If the size of array is n then index ranges from 0 to n-1. There can be array of integer,
floating point or character values. Character array is called as String.
Eg.1 A=
0 1 2 3 4
This example illustrates integer array A of size 5.
 Array index ranges from 0 to 4.
 Elements of array are {10, 20, 40, 5, 25}.
Arrays can be categorized in following types
1. One dimensional array
2. Multi Dimensional array
These are described below.
The abstract model of string is implemented by defining a character array data type and
we need to include header file ‘string.h’, to hold all the relevant operations of string. The
string header file enables user to view complete string and perform various operation
on the string. E.g. we can call ‘strlen’ function to find length of string, ‘strcat’ to
concatenate two string, ‘strcpy’ to copy one string to another, ‘strrev’ to reverse the
string. The definitions of all these functions are stored in the header file ‘string.h’. So
string functions with the user provided data becomes the new data type in ‘C’.
Fig. 3.1 : String data type
To use the functions related to strings, user only need to include ‘string.h’ header file.
All the definitions details of these functions are keep hidden from the user, user can
directly use these function without knowing all the implementation details. This is known
as abstraction or hiding.
String Manipulation in C Language
Strings are also called as the array of character.
 A special character usually known as null character (0) is used to indicate the end
of the string.
 To read and write the string in C program %s access specifier is required.
 C language provides several built in functions for the manipulation of the string
 To use the built in functions for string, user need to include string.h header file.
 Syntax for declaring string is
Char string name[size of string];
Char is the data type, user can give any name to the string by following all the rules of
defining name of variable. Size of the string is the number of alphabet user wants to
store in string.
Example:
Sr. No. Instructions Description
1. #include<stdio.h> Header file included
2. #include<conio.h
>
Header file included
3. void main() Execution of program begins
4. { String is declare with name str and size of
storing 10 alphbates
5. char str[10];
6. clrscr(); Clear the output of previous screen
7. printf("enter a
string");
Print “enter a string”
8. scanf("%s",&str); Entered string is stored at address of str
9. printf("n user
entered string is
%s",str);
Print: user entered string is (string entered
by user)
10. getch(); Used to hold the output screen
11. } Indicates end of scope of main function
Following are the list of string manipulation function
Sr. No.
String
Function
Purpose
1. strcat use to concatenate (append) one string to
another
2. Strcmp use to compare one string with another.
(Note: The comparison is case sensitive)
3. strchr use to locate the first occurrence of a particular
character in a given string
4. Strcpy use to copy one string to another.
5. Strlen use to find the length of a string in bytes,

More Related Content

Similar to PPS 4.4ARRAYS ARRAY DECLARATION & INITIALIZATION, BOUND CHECKING ARRAYS (1-D, 2-D), CHARACTER ARRAYS AND STRINGS. (20)

Unit ii data structure-converted
Unit  ii data structure-convertedUnit  ii data structure-converted
Unit ii data structure-converted
Shri Shankaracharya College, Bhilai,Junwani
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
nmahi96
 
Array assignment
Array assignmentArray assignment
Array assignment
Ahmad Kamal
 
Array
ArrayArray
Array
hjasjhd
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
Anurag University Hyderabad
 
Session 7 En
Session 7 EnSession 7 En
Session 7 En
guest91d2b3
 
Session 7 En
Session 7 EnSession 7 En
Session 7 En
SamQuiDaiBo
 
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
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptx
JawadTanvir
 
Arrays
ArraysArrays
Arrays
ViniVini48
 
Module 4- Arrays and Strings
Module 4- Arrays and StringsModule 4- Arrays and Strings
Module 4- Arrays and Strings
nikshaikh786
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdf
HimanshuKansal22
 
presentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.pptpresentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.ppt
NamakkalPasanga
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
YOGESH SINGH
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
Kashif Nawab
 
6.array
6.array6.array
6.array
Shankar Gangaju
 
Array In C++ programming object oriented programming
Array In C++ programming object oriented programmingArray In C++ programming object oriented programming
Array In C++ programming object oriented programming
Ahmad177077
 
Array
ArrayArray
Array
Shankar Gangaju
 
Array, string and pointer
Array, string and pointerArray, string and pointer
Array, string and pointer
Nishant Munjal
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
Swarup Boro
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
nmahi96
 
Array assignment
Array assignmentArray assignment
Array assignment
Ahmad Kamal
 
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
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptx
JawadTanvir
 
Module 4- Arrays and Strings
Module 4- Arrays and StringsModule 4- Arrays and Strings
Module 4- Arrays and Strings
nikshaikh786
 
presentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.pptpresentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.ppt
NamakkalPasanga
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
YOGESH SINGH
 
Array In C++ programming object oriented programming
Array In C++ programming object oriented programmingArray In C++ programming object oriented programming
Array In C++ programming object oriented programming
Ahmad177077
 
Array, string and pointer
Array, string and pointerArray, string and pointer
Array, string and pointer
Nishant Munjal
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
Swarup Boro
 

More from Sitamarhi Institute of Technology (20)

STET 2025 900+ Computer MCQs in English PDF (studynotes.online).pdf
STET 2025 900+ Computer MCQs in English PDF (studynotes.online).pdfSTET 2025 900+ Computer MCQs in English PDF (studynotes.online).pdf
STET 2025 900+ Computer MCQs in English PDF (studynotes.online).pdf
Sitamarhi Institute of Technology
 
DeepSeek vs. ChatGPT - The Battle of AI Titans.pdf
DeepSeek vs. ChatGPT - The Battle of AI Titans.pdfDeepSeek vs. ChatGPT - The Battle of AI Titans.pdf
DeepSeek vs. ChatGPT - The Battle of AI Titans.pdf
Sitamarhi Institute of Technology
 
METHODS OF CUTTING COPYING HTML BASIC NOTES
METHODS OF CUTTING COPYING HTML BASIC  NOTESMETHODS OF CUTTING COPYING HTML BASIC  NOTES
METHODS OF CUTTING COPYING HTML BASIC NOTES
Sitamarhi Institute of Technology
 
introduction Printer basic notes Hindi and English
introduction Printer basic notes Hindi and Englishintroduction Printer basic notes Hindi and English
introduction Printer basic notes Hindi and English
Sitamarhi Institute of Technology
 
Beginners Guide to Microsoft OneDrive 2024–2025.pdf
Beginners Guide to Microsoft OneDrive 2024–2025.pdfBeginners Guide to Microsoft OneDrive 2024–2025.pdf
Beginners Guide to Microsoft OneDrive 2024–2025.pdf
Sitamarhi Institute of Technology
 
ChatGPT Foundations rompts given for each topic in both personal and business...
ChatGPT Foundations rompts given for each topic in both personal and business...ChatGPT Foundations rompts given for each topic in both personal and business...
ChatGPT Foundations rompts given for each topic in both personal and business...
Sitamarhi Institute of Technology
 
Google Drive Mastery Guide for Beginners.pdf
Google Drive Mastery Guide for Beginners.pdfGoogle Drive Mastery Guide for Beginners.pdf
Google Drive Mastery Guide for Beginners.pdf
Sitamarhi Institute of Technology
 
Chat GPT 1000+ Prompts - Chat GPT Prompts .pdf
Chat GPT 1000+ Prompts - Chat GPT Prompts .pdfChat GPT 1000+ Prompts - Chat GPT Prompts .pdf
Chat GPT 1000+ Prompts - Chat GPT Prompts .pdf
Sitamarhi Institute of Technology
 
Smart Phone Film Making.filmmaking but feel limited by the constraints of exp...
Smart Phone Film Making.filmmaking but feel limited by the constraints of exp...Smart Phone Film Making.filmmaking but feel limited by the constraints of exp...
Smart Phone Film Making.filmmaking but feel limited by the constraints of exp...
Sitamarhi Institute of Technology
 
WhatsApp Tricks and Tips - 20th Edition 2024.pdf
WhatsApp Tricks and Tips - 20th Edition 2024.pdfWhatsApp Tricks and Tips - 20th Edition 2024.pdf
WhatsApp Tricks and Tips - 20th Edition 2024.pdf
Sitamarhi Institute of Technology
 
Mastering ChatGPT for Creative Ideas Generation.pdf
Mastering ChatGPT for Creative Ideas Generation.pdfMastering ChatGPT for Creative Ideas Generation.pdf
Mastering ChatGPT for Creative Ideas Generation.pdf
Sitamarhi Institute of Technology
 
BASIC COMPUTER CONCEPTSMADE BY: SIR SAROJ KUMAR
BASIC COMPUTER CONCEPTSMADE BY: SIR SAROJ KUMARBASIC COMPUTER CONCEPTSMADE BY: SIR SAROJ KUMAR
BASIC COMPUTER CONCEPTSMADE BY: SIR SAROJ KUMAR
Sitamarhi Institute of Technology
 
MS Word tutorial provides basic and advanced concepts of Word.
MS Word tutorial provides basic and advanced concepts of Word.MS Word tutorial provides basic and advanced concepts of Word.
MS Word tutorial provides basic and advanced concepts of Word.
Sitamarhi Institute of Technology
 
BELTRON_PROGRAMMER 2018 and 2019 previous papers
BELTRON_PROGRAMMER 2018 and 2019  previous papersBELTRON_PROGRAMMER 2018 and 2019  previous papers
BELTRON_PROGRAMMER 2018 and 2019 previous papers
Sitamarhi Institute of Technology
 
CORPORATE SOCIAL RESPONSIBILITY CSR) through a presentation by R.K. Sahoo
CORPORATE SOCIAL RESPONSIBILITY  CSR) through a presentation by R.K. SahooCORPORATE SOCIAL RESPONSIBILITY  CSR) through a presentation by R.K. Sahoo
CORPORATE SOCIAL RESPONSIBILITY CSR) through a presentation by R.K. Sahoo
Sitamarhi Institute of Technology
 
Enhancing-digital-engagement-integrating-storytelling-
Enhancing-digital-engagement-integrating-storytelling-Enhancing-digital-engagement-integrating-storytelling-
Enhancing-digital-engagement-integrating-storytelling-
Sitamarhi Institute of Technology
 
business-with-innovative email-marketing-solution-
business-with-innovative email-marketing-solution-business-with-innovative email-marketing-solution-
business-with-innovative email-marketing-solution-
Sitamarhi Institute of Technology
 
MS Excel Notes PDF in Hindi माइोसॉट एसेल
MS Excel Notes PDF in Hindi माइोसॉट एसेलMS Excel Notes PDF in Hindi माइोसॉट एसेल
MS Excel Notes PDF in Hindi माइोसॉट एसेल
Sitamarhi Institute of Technology
 
beltron-programmer-2023-previous-year-question.pdf
beltron-programmer-2023-previous-year-question.pdfbeltron-programmer-2023-previous-year-question.pdf
beltron-programmer-2023-previous-year-question.pdf
Sitamarhi Institute of Technology
 
Beltron Programmer IGNOU-MCA-NEW-Syllabus.pdf
Beltron Programmer IGNOU-MCA-NEW-Syllabus.pdfBeltron Programmer IGNOU-MCA-NEW-Syllabus.pdf
Beltron Programmer IGNOU-MCA-NEW-Syllabus.pdf
Sitamarhi Institute of Technology
 
STET 2025 900+ Computer MCQs in English PDF (studynotes.online).pdf
STET 2025 900+ Computer MCQs in English PDF (studynotes.online).pdfSTET 2025 900+ Computer MCQs in English PDF (studynotes.online).pdf
STET 2025 900+ Computer MCQs in English PDF (studynotes.online).pdf
Sitamarhi Institute of Technology
 
ChatGPT Foundations rompts given for each topic in both personal and business...
ChatGPT Foundations rompts given for each topic in both personal and business...ChatGPT Foundations rompts given for each topic in both personal and business...
ChatGPT Foundations rompts given for each topic in both personal and business...
Sitamarhi Institute of Technology
 
Smart Phone Film Making.filmmaking but feel limited by the constraints of exp...
Smart Phone Film Making.filmmaking but feel limited by the constraints of exp...Smart Phone Film Making.filmmaking but feel limited by the constraints of exp...
Smart Phone Film Making.filmmaking but feel limited by the constraints of exp...
Sitamarhi Institute of Technology
 
MS Word tutorial provides basic and advanced concepts of Word.
MS Word tutorial provides basic and advanced concepts of Word.MS Word tutorial provides basic and advanced concepts of Word.
MS Word tutorial provides basic and advanced concepts of Word.
Sitamarhi Institute of Technology
 
CORPORATE SOCIAL RESPONSIBILITY CSR) through a presentation by R.K. Sahoo
CORPORATE SOCIAL RESPONSIBILITY  CSR) through a presentation by R.K. SahooCORPORATE SOCIAL RESPONSIBILITY  CSR) through a presentation by R.K. Sahoo
CORPORATE SOCIAL RESPONSIBILITY CSR) through a presentation by R.K. Sahoo
Sitamarhi Institute of Technology
 
MS Excel Notes PDF in Hindi माइोसॉट एसेल
MS Excel Notes PDF in Hindi माइोसॉट एसेलMS Excel Notes PDF in Hindi माइोसॉट एसेल
MS Excel Notes PDF in Hindi माइोसॉट एसेल
Sitamarhi Institute of Technology
 
Ad

Recently uploaded (20)

Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant ConversionStructural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
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
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
Blood bank management system project report.pdf
Blood bank management system project report.pdfBlood bank management system project report.pdf
Blood bank management system project report.pdf
Kamal Acharya
 
ACEP Magazine Fifth Edition on 5june2025
ACEP Magazine Fifth Edition on 5june2025ACEP Magazine Fifth Edition on 5june2025
ACEP Magazine Fifth Edition on 5june2025
Rahul
 
Impurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptxImpurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptx
dhanashree78
 
First Come First Serve Scheduling in real time operating system.pptx
First Come First Serve Scheduling in real time operating system.pptxFirst Come First Serve Scheduling in real time operating system.pptx
First Come First Serve Scheduling in real time operating system.pptx
KavitaBagewadi2
 
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
 
OCS Group SG - HPHT Well Design and Operation - SN.pdf
OCS Group SG - HPHT Well Design and Operation - SN.pdfOCS Group SG - HPHT Well Design and Operation - SN.pdf
OCS Group SG - HPHT Well Design and Operation - SN.pdf
Muanisa Waras
 
4th International Conference on Computer Science and Information Technology (...
4th International Conference on Computer Science and Information Technology (...4th International Conference on Computer Science and Information Technology (...
4th International Conference on Computer Science and Information Technology (...
ijait
 
Présentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptxPrésentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptx
KHADIJAESSAKET
 
22PCOAM16 _ML_Unit 3 Notes & Question bank
22PCOAM16 _ML_Unit 3 Notes & Question bank22PCOAM16 _ML_Unit 3 Notes & Question bank
22PCOAM16 _ML_Unit 3 Notes & Question bank
Guru Nanak Technical Institutions
 
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
Journal of Soft Computing in Civil Engineering
 
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
 
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
 
Center Enamel can Provide Aluminum Dome Roofs for diesel tank.docx
Center Enamel can Provide Aluminum Dome Roofs for  diesel tank.docxCenter Enamel can Provide Aluminum Dome Roofs for  diesel tank.docx
Center Enamel can Provide Aluminum Dome Roofs for diesel tank.docx
CenterEnamel
 
IntroSlides-June-GDG-Cloud-Munich community [email protected]
IntroSlides-June-GDG-Cloud-Munich community gathering@Netlight.pdfIntroSlides-June-GDG-Cloud-Munich community gathering@Netlight.pdf
IntroSlides-June-GDG-Cloud-Munich community [email protected]
Luiz Carneiro
 
最新版美国圣莫尼卡学院毕业证(SMC毕业证书)原版定制
最新版美国圣莫尼卡学院毕业证(SMC毕业证书)原版定制最新版美国圣莫尼卡学院毕业证(SMC毕业证书)原版定制
最新版美国圣莫尼卡学院毕业证(SMC毕业证书)原版定制
Taqyea
 
TEA2016AAT 160 W TV application design example
TEA2016AAT 160 W TV application design exampleTEA2016AAT 160 W TV application design example
TEA2016AAT 160 W TV application design example
ssuser1be9ce
 
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptxDevelopment of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
aniket862935
 
Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant ConversionStructural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
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
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
Blood bank management system project report.pdf
Blood bank management system project report.pdfBlood bank management system project report.pdf
Blood bank management system project report.pdf
Kamal Acharya
 
ACEP Magazine Fifth Edition on 5june2025
ACEP Magazine Fifth Edition on 5june2025ACEP Magazine Fifth Edition on 5june2025
ACEP Magazine Fifth Edition on 5june2025
Rahul
 
Impurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptxImpurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptx
dhanashree78
 
First Come First Serve Scheduling in real time operating system.pptx
First Come First Serve Scheduling in real time operating system.pptxFirst Come First Serve Scheduling in real time operating system.pptx
First Come First Serve Scheduling in real time operating system.pptx
KavitaBagewadi2
 
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
 
OCS Group SG - HPHT Well Design and Operation - SN.pdf
OCS Group SG - HPHT Well Design and Operation - SN.pdfOCS Group SG - HPHT Well Design and Operation - SN.pdf
OCS Group SG - HPHT Well Design and Operation - SN.pdf
Muanisa Waras
 
4th International Conference on Computer Science and Information Technology (...
4th International Conference on Computer Science and Information Technology (...4th International Conference on Computer Science and Information Technology (...
4th International Conference on Computer Science and Information Technology (...
ijait
 
Présentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptxPrésentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptx
KHADIJAESSAKET
 
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
 
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
 
Center Enamel can Provide Aluminum Dome Roofs for diesel tank.docx
Center Enamel can Provide Aluminum Dome Roofs for  diesel tank.docxCenter Enamel can Provide Aluminum Dome Roofs for  diesel tank.docx
Center Enamel can Provide Aluminum Dome Roofs for diesel tank.docx
CenterEnamel
 
最新版美国圣莫尼卡学院毕业证(SMC毕业证书)原版定制
最新版美国圣莫尼卡学院毕业证(SMC毕业证书)原版定制最新版美国圣莫尼卡学院毕业证(SMC毕业证书)原版定制
最新版美国圣莫尼卡学院毕业证(SMC毕业证书)原版定制
Taqyea
 
TEA2016AAT 160 W TV application design example
TEA2016AAT 160 W TV application design exampleTEA2016AAT 160 W TV application design example
TEA2016AAT 160 W TV application design example
ssuser1be9ce
 
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptxDevelopment of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
Development of Portable Biomass Briquetting Machine (S, A & D)-1.pptx
aniket862935
 
Ad

PPS 4.4ARRAYS ARRAY DECLARATION & INITIALIZATION, BOUND CHECKING ARRAYS (1-D, 2-D), CHARACTER ARRAYS AND STRINGS.

  • 1. PPS Unit – 4 Arrays 4.1 Array Declaration & Initialization Array is defined as a collection of elements of same data type. Hence it is also called as homogeneous variable. Total number of elements in array defines size of array. Position of element in an array defines index or subscript of particular element. Array index always starts with zero. 4.2 Bound Checking Arrays (1-D, 2-D) 1. One Dimensional Array: The array which is used to represent and store data in a linear form is called as 'single or one dimensional array.' Syntax: data-typearray_name[size]; Example 2: int a[3] = {2, 3, 5}; charch[10] = "Data" ; float x[3] = {2.5, 3.50,489.98} ; Total Size of an array(in Bytes) can be calculated as follows: total size(in bytes) = length of array * size of data type
  • 2. In above example, a is an array of type integer which has storage size of 3 elements. One integer variable occupies 2 bytes. Hence the total size would be 3 * 2 = 6 bytes. Memory Allocation : P1: Program to display all elements of 1-D array. #include<stdio.h> #include<conio.h> void main() { int a[20]; intn,i; printf("n Enter the size of array :"); scanf("%d",&n); printf("size of array is %d",n); printf("n Enter Values to store in array one by one by pressing ENTER :"); for(i=0;i<n;i++) { scanf("%d",&a[i]); } printf("n The Values in array are.."); for(i=0;i<n;i++) { printf("n %d",a[i]); } getch(); }
  • 4. P2: Program to copy 1-D array to another 1-D array #include <stdio.h> #include<conio.h> void main() { int n, i, j, a[100], b[100];// a is original array and b is copied array printf("Enter the number of elements in array an"); scanf("%d", &n); printf("Enter the array elements in an"); for (i= 0; i< n ; i++) scanf("%d", &a[i]); /* Copying elements from array a into array b */ for (i =0;i<n;i++) b[i] = a[i];
  • 5. /* Printing copied array b . */ printf("Elements of array b aren"); for (i = 0; i< n; i++) printf("%dn", b[i]); getch(); } Output
  • 6. P3:Program to find reverse of 1-D array #include <stdio.h> #include<conio.h> void main() { int n, i, j, a[100], b[100];// a is original array and b is reversed array printf("Enter the number of elements in arrayn");
  • 7. scanf("%d", &n); printf("Enter the array elementsn"); for (i= 0; i< n ; i++) scanf("%d", &a[i]); /* * Copying elements into array b starting from end of array a */ for (i = n - 1, j = 0; i>= 0; i--, j++) b[j] = a[i]; /* Printing reversed array b . */ printf("Reverse array isn"); for (i = 0; i< n; i++) printf("%dn", a[i]); getch(); } Output:
  • 9. 2. Multi Dimensional Array 1-D array has 1 row and multiple columns but multidimensional array has of multiple rows and multiple columns. Two Dimensional array: Itis the simplest multidimensional array. They are also called as matrix.
  • 10. Declaration: data-typearray_name[no.of rows][no. of columns]; Total no of elements= No.of rows * No. of Columns Example 3: inta[2][3] This example illustrates two dimensional array a of 2 rows and 3 columns. Total no of elements: 2*3=6 Total no of bytes occupied: 6( totalno.of elements )*2(Size of one element)=12 Initialization and Storage Representation: In C, two dimensional arrays can be initialized in different number of ways. Specification of no. of columns in 2 dimensional array is mandatory while no of rows is optional. int a[2][3]={{1,3,0}, // Elements of 1st row {-1,5,9}}; // Elements of 2nd row OR int a[][3]={{1,3,0}, // Elements of 1st row {-1,5,9}}; // Elements of 2nd row
  • 11. OR int a[2][3]={1,3,0,-1,5,9}; Fig. 3 gives general storage representation of 2 dimensional array Eg 4. int a[2][3]={1,3,0,-1,5,9}
  • 12. Accessing Two-Dimensional Array Elements: An element in 2-dimensional array is accessed by using the subscripts i.e. row index and column index of the array. For example: intval= A[1][2]; The above statement will access element from the 2nd row and third column of the array A i.e. element 9. 4.3 Character Arrays And Strings If the size of array is n then index ranges from 0 to n-1. There can be array of integer, floating point or character values. Character array is called as String. Eg.1 A= 0 1 2 3 4 This example illustrates integer array A of size 5.  Array index ranges from 0 to 4.  Elements of array are {10, 20, 40, 5, 25}.
  • 13. Arrays can be categorized in following types 1. One dimensional array 2. Multi Dimensional array These are described below. The abstract model of string is implemented by defining a character array data type and we need to include header file ‘string.h’, to hold all the relevant operations of string. The string header file enables user to view complete string and perform various operation on the string. E.g. we can call ‘strlen’ function to find length of string, ‘strcat’ to concatenate two string, ‘strcpy’ to copy one string to another, ‘strrev’ to reverse the string. The definitions of all these functions are stored in the header file ‘string.h’. So string functions with the user provided data becomes the new data type in ‘C’. Fig. 3.1 : String data type To use the functions related to strings, user only need to include ‘string.h’ header file. All the definitions details of these functions are keep hidden from the user, user can directly use these function without knowing all the implementation details. This is known as abstraction or hiding. String Manipulation in C Language Strings are also called as the array of character.
  • 14.  A special character usually known as null character (0) is used to indicate the end of the string.  To read and write the string in C program %s access specifier is required.  C language provides several built in functions for the manipulation of the string  To use the built in functions for string, user need to include string.h header file.  Syntax for declaring string is Char string name[size of string]; Char is the data type, user can give any name to the string by following all the rules of defining name of variable. Size of the string is the number of alphabet user wants to store in string. Example: Sr. No. Instructions Description 1. #include<stdio.h> Header file included 2. #include<conio.h > Header file included 3. void main() Execution of program begins 4. { String is declare with name str and size of storing 10 alphbates 5. char str[10]; 6. clrscr(); Clear the output of previous screen 7. printf("enter a string"); Print “enter a string” 8. scanf("%s",&str); Entered string is stored at address of str 9. printf("n user entered string is %s",str); Print: user entered string is (string entered by user) 10. getch(); Used to hold the output screen 11. } Indicates end of scope of main function Following are the list of string manipulation function Sr. No. String Function Purpose 1. strcat use to concatenate (append) one string to another
  • 15. 2. Strcmp use to compare one string with another. (Note: The comparison is case sensitive) 3. strchr use to locate the first occurrence of a particular character in a given string 4. Strcpy use to copy one string to another. 5. Strlen use to find the length of a string in bytes,