SlideShare a Scribd company logo
Arrays
∗ Introduction to Arrays
∗ One-Dimensional Arrays
∗ Declaration of One-Dimensional Arrays
∗ Initialization of One-Dimensional Arrays
Arrays
∗ Basic data types are
constrained by the fact that only one value can be stored.
eg; int x=2;
∗ If you need a large of volume data to be handled , array is
essential.
∗ An array is a fixed-size sequenced collection of elements of
the same data type.
∗ Types of arrays:
1- one-dimensional array
2- two-dimensional array
3- multidimensional array
Introduction to Arrays
∗ General form of declaration :
type variable-name[size];
e.g.
int x[10];
Note:
∗ – type can be any type (int, float, char, …)
∗ – array name is an identifier
∗
Declaration of
One-Dimensional Arrays
How the computer prepare space
(memory)
The value to the array elements can be assigned as follows
x[0] = 95 ;
x[1] = 93 ;
x[2] = 94 ;
x[3] = 96 ;
x[4] = 97 ;
x[5] = 92 ;
x[6] = 91 ;
x[7] = 100 ;
x[8] = 99 ;
x[9] = 98 ;
A list of items can be given one variable name using only one
subscript such variable is called One-dimentional array.
int x[10];
∗ Elements in an array must be initialized after it is declared,
otherwise they will contain “garbage”.
∗ An array can be initialized with two ways:
∗ 1- At compile time (when writing the code)
∗ 2- At run time ( excution time )
Initialization of One-
Dimensional Arrays
∗ Compile Time Initialization
∗ General form:
type array-name[size] = {list of values};
e.g.
int x[10]={6,5,9,3,2,3,1,8,6,4};
int number[] = {9,3,2};
float mark[5] = {2.3,3.04,4.5,56.0,6};
char name[] = {‘J’,’A’,’C’,’K’}; or “JACK”
int number[5] = {1,2}; // remain 0
char name[10] = {‘J’,’A’,’C’,’K’} ; // remain null
int array[3] = {1,2,3,4} ; // illegal
Initialization of One-Dimensional
Arrays
∗ Runtime Initialization(large size array)
………
int array[100];
for(int j = 0; j < 100; ++j)
{
if(j < 50) array[j] = 0;
else array[j] = 1;
}
Initialization of One-Dimensional
Arrays
∗ Runtime Initialization
∗ Using scanf
. . . . . . Int x[4];
scanf(“%d%d%d%d”, &x[0], &x[1], &x[2], &x[3]);
Initialization of One-Dimensional Arrays
∗ Runtime initialization
∗ Using scanf
. . . . . . . .
int x[4],i;
for(i=0;i<4;i++)
{scanf(“%d”,&x[i]);}
}
Initialization of One-Dimensional Arrays
∗ Read 10 students’ marks, calculate the average
void main()
{
float mark[10]; // declaring an array
float total = 0; // declaring avariable
for(int i = 0; i < 10; i++) // counter loop
scanf(“%f”,&mark[i]); // initializing the array
for(int j = 0; j < 10; j++) // counter loop
total += mark[j]; // initializing the variable
printf(“average = %f”, total/10);
}
One-Dimensional Arrays
contact:- sayidsuleiman01@gmail.com
Thank
you

More Related Content

PPTX
Array in c
PPTX
Array in c
PPT
7.basic array
PPTX
Array in C
PDF
Lecture17 arrays.ppt
PPSX
C Programming : Arrays
PPTX
Array in c language
PPTX
Array in C
Array in c
Array in c
7.basic array
Array in C
Lecture17 arrays.ppt
C Programming : Arrays
Array in c language
Array in C

What's hot (20)

PPTX
Introduction to Array ppt
PPTX
PPTX
Array in-c
PPTX
Array in c language
PDF
Prediction of Skierdays with Oracle Data Mining - Analytics and Data Techcast...
PDF
Prediction of Skierdays With Oracle Data Mining - OGB EMEA Edition
PPTX
Basic array in c programming
PDF
Numpy Meetup 07/02/2013
PPTX
Arrays in c
PPTX
Array,MULTI ARRAY, IN C
PPTX
Arrays In C Language
PPTX
Array in c language
PPTX
Array in c programming
PPTX
Session11 single dimarrays
PPTX
Array in c language
PPT
Dynamic memory allocation
PPTX
Array in c programming
PPTX
PPTX
Array in (C) programing
PPTX
Pointers and Dynamic Memory Allocation
Introduction to Array ppt
Array in-c
Array in c language
Prediction of Skierdays with Oracle Data Mining - Analytics and Data Techcast...
Prediction of Skierdays With Oracle Data Mining - OGB EMEA Edition
Basic array in c programming
Numpy Meetup 07/02/2013
Arrays in c
Array,MULTI ARRAY, IN C
Arrays In C Language
Array in c language
Array in c programming
Session11 single dimarrays
Array in c language
Dynamic memory allocation
Array in c programming
Array in (C) programing
Pointers and Dynamic Memory Allocation
Ad

Similar to Presentation about arrays (20)

PPTX
C (PPS)Programming for problem solving.pptx
PPTX
Array definition and uses in computer.pptx
PPTX
Introduction to Array & Structure & Basic Algorithms.pptx
PPT
arrays used for data structures and algorithms
PDF
PPS SSSSHHEHESHSHEHHEHAKAKHEHE12131415.pdf
PPT
ReviewArrays.ppt
PPT
Use syntax highlighting for C++ code (via plugins like "Highlight Code" for P...
PDF
SPL 12 | Multi-dimensional Array in C
PPTX
Array , Structure and Basic Algorithms.pptx
PPT
Lecture 15 - Array
PPTX
Arrays 1D and 2D , and multi dimensional
PPT
Two dimensional array
PPTX
ARRAYSCPP.pptx
PPT
Arrays
PPT
L10 array
PDF
array-191103180006.pdf
PPTX
Array Introduction One-dimensional array Multidimensional array
PDF
Arrays and library functions
PDF
javaarray
DOC
Arrays and Strings
C (PPS)Programming for problem solving.pptx
Array definition and uses in computer.pptx
Introduction to Array & Structure & Basic Algorithms.pptx
arrays used for data structures and algorithms
PPS SSSSHHEHESHSHEHHEHAKAKHEHE12131415.pdf
ReviewArrays.ppt
Use syntax highlighting for C++ code (via plugins like "Highlight Code" for P...
SPL 12 | Multi-dimensional Array in C
Array , Structure and Basic Algorithms.pptx
Lecture 15 - Array
Arrays 1D and 2D , and multi dimensional
Two dimensional array
ARRAYSCPP.pptx
Arrays
L10 array
array-191103180006.pdf
Array Introduction One-dimensional array Multidimensional array
Arrays and library functions
javaarray
Arrays and Strings
Ad

Recently uploaded (20)

PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
composite construction of structures.pdf
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Construction Project Organization Group 2.pptx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Artificial Intelligence
PPT
Mechanical Engineering MATERIALS Selection
DOCX
573137875-Attendance-Management-System-original
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
additive manufacturing of ss316l using mig welding
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPT
introduction to datamining and warehousing
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
Geodesy 1.pptx...............................................
bas. eng. economics group 4 presentation 1.pptx
composite construction of structures.pdf
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Construction Project Organization Group 2.pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Internet of Things (IOT) - A guide to understanding
Foundation to blockchain - A guide to Blockchain Tech
Artificial Intelligence
Mechanical Engineering MATERIALS Selection
573137875-Attendance-Management-System-original
Model Code of Practice - Construction Work - 21102022 .pdf
Operating System & Kernel Study Guide-1 - converted.pdf
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
additive manufacturing of ss316l using mig welding
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
introduction to datamining and warehousing
R24 SURVEYING LAB MANUAL for civil enggi
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
CYBER-CRIMES AND SECURITY A guide to understanding
Geodesy 1.pptx...............................................

Presentation about arrays

  • 2. ∗ Introduction to Arrays ∗ One-Dimensional Arrays ∗ Declaration of One-Dimensional Arrays ∗ Initialization of One-Dimensional Arrays Arrays
  • 3. ∗ Basic data types are constrained by the fact that only one value can be stored. eg; int x=2; ∗ If you need a large of volume data to be handled , array is essential. ∗ An array is a fixed-size sequenced collection of elements of the same data type. ∗ Types of arrays: 1- one-dimensional array 2- two-dimensional array 3- multidimensional array Introduction to Arrays
  • 4. ∗ General form of declaration : type variable-name[size]; e.g. int x[10]; Note: ∗ – type can be any type (int, float, char, …) ∗ – array name is an identifier ∗ Declaration of One-Dimensional Arrays
  • 5. How the computer prepare space (memory)
  • 6. The value to the array elements can be assigned as follows x[0] = 95 ; x[1] = 93 ; x[2] = 94 ; x[3] = 96 ; x[4] = 97 ; x[5] = 92 ; x[6] = 91 ; x[7] = 100 ; x[8] = 99 ; x[9] = 98 ;
  • 7. A list of items can be given one variable name using only one subscript such variable is called One-dimentional array. int x[10];
  • 8. ∗ Elements in an array must be initialized after it is declared, otherwise they will contain “garbage”. ∗ An array can be initialized with two ways: ∗ 1- At compile time (when writing the code) ∗ 2- At run time ( excution time ) Initialization of One- Dimensional Arrays
  • 9. ∗ Compile Time Initialization ∗ General form: type array-name[size] = {list of values}; e.g. int x[10]={6,5,9,3,2,3,1,8,6,4}; int number[] = {9,3,2}; float mark[5] = {2.3,3.04,4.5,56.0,6}; char name[] = {‘J’,’A’,’C’,’K’}; or “JACK” int number[5] = {1,2}; // remain 0 char name[10] = {‘J’,’A’,’C’,’K’} ; // remain null int array[3] = {1,2,3,4} ; // illegal Initialization of One-Dimensional Arrays
  • 10. ∗ Runtime Initialization(large size array) ……… int array[100]; for(int j = 0; j < 100; ++j) { if(j < 50) array[j] = 0; else array[j] = 1; } Initialization of One-Dimensional Arrays
  • 11. ∗ Runtime Initialization ∗ Using scanf . . . . . . Int x[4]; scanf(“%d%d%d%d”, &x[0], &x[1], &x[2], &x[3]); Initialization of One-Dimensional Arrays
  • 12. ∗ Runtime initialization ∗ Using scanf . . . . . . . . int x[4],i; for(i=0;i<4;i++) {scanf(“%d”,&x[i]);} } Initialization of One-Dimensional Arrays
  • 13. ∗ Read 10 students’ marks, calculate the average void main() { float mark[10]; // declaring an array float total = 0; // declaring avariable for(int i = 0; i < 10; i++) // counter loop scanf(“%f”,&mark[i]); // initializing the array for(int j = 0; j < 10; j++) // counter loop total += mark[j]; // initializing the variable printf(“average = %f”, total/10); } One-Dimensional Arrays