際際滷

際際滷Share 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

What's hot (20)

Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
sandhya yadav
Array
ArrayArray
Array
Allah Ditta
Array in-c
Array in-cArray in-c
Array in-c
Samsil Arefin
Array in c language
Array in c language Array in c language
Array in c language
umesh patil
Prediction of Skierdays with Oracle Data Mining - Analytics and Data Techcast...
Prediction of Skierdays with Oracle Data Mining - Analytics and Data Techcast...Prediction of Skierdays with Oracle Data Mining - Analytics and Data Techcast...
Prediction of Skierdays with Oracle Data Mining - Analytics and Data Techcast...
Jasmin Fluri
Prediction of Skierdays With Oracle Data Mining - OGB EMEA Edition
Prediction of Skierdays With Oracle Data Mining - OGB EMEA EditionPrediction of Skierdays With Oracle Data Mining - OGB EMEA Edition
Prediction of Skierdays With Oracle Data Mining - OGB EMEA Edition
Jasmin Fluri
Basic array in c programming
Basic array in c programmingBasic array in c programming
Basic array in c programming
Sajid Hasan
Numpy Meetup 07/02/2013
Numpy Meetup 07/02/2013Numpy Meetup 07/02/2013
Numpy Meetup 07/02/2013
Francesco
Arrays in c
Arrays in cArrays in c
Arrays in c
Jeeva Nanthini
Array,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN CArray,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN C
naveed jamali
Arrays In C Language
Arrays In C LanguageArrays In C Language
Arrays In C Language
Surbhi Yadav
Array in c language
Array in c languageArray in c language
Array in c language
home
Array in c programming
Array in c programmingArray in c programming
Array in c programming
Mazharul Islam
Session11 single dimarrays
Session11 single dimarraysSession11 single dimarrays
Session11 single dimarrays
HarithaRanasinghe
Array in c language
Array in c language Array in c language
Array in c language
umesh patil
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
Naveen Gupta
Array in c programming
Array in c programmingArray in c programming
Array in c programming
2569294Mohan
Arrays
ArraysArrays
Arrays
Saran Ravichandran
Array in (C) programing
Array in (C) programing Array in (C) programing
Array in (C) programing
mJafarww
Pointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory Allocation
Rabin BK
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
sandhya yadav
Array in c language
Array in c language Array in c language
Array in c language
umesh patil
Prediction of Skierdays with Oracle Data Mining - Analytics and Data Techcast...
Prediction of Skierdays with Oracle Data Mining - Analytics and Data Techcast...Prediction of Skierdays with Oracle Data Mining - Analytics and Data Techcast...
Prediction of Skierdays with Oracle Data Mining - Analytics and Data Techcast...
Jasmin Fluri
Prediction of Skierdays With Oracle Data Mining - OGB EMEA Edition
Prediction of Skierdays With Oracle Data Mining - OGB EMEA EditionPrediction of Skierdays With Oracle Data Mining - OGB EMEA Edition
Prediction of Skierdays With Oracle Data Mining - OGB EMEA Edition
Jasmin Fluri
Basic array in c programming
Basic array in c programmingBasic array in c programming
Basic array in c programming
Sajid Hasan
Numpy Meetup 07/02/2013
Numpy Meetup 07/02/2013Numpy Meetup 07/02/2013
Numpy Meetup 07/02/2013
Francesco
Array,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN CArray,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN C
naveed jamali
Arrays In C Language
Arrays In C LanguageArrays In C Language
Arrays In C Language
Surbhi Yadav
Array in c language
Array in c languageArray in c language
Array in c language
home
Array in c programming
Array in c programmingArray in c programming
Array in c programming
Mazharul Islam
Session11 single dimarrays
Session11 single dimarraysSession11 single dimarrays
Session11 single dimarrays
HarithaRanasinghe
Array in c language
Array in c language Array in c language
Array in c language
umesh patil
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
Naveen Gupta
Array in c programming
Array in c programmingArray in c programming
Array in c programming
2569294Mohan
Array in (C) programing
Array in (C) programing Array in (C) programing
Array in (C) programing
mJafarww
Pointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory Allocation
Rabin BK

Similar to Presentation about arrays (20)

C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
rohinitalekar1
Array definition and uses in computer.pptx
Array definition and uses in computer.pptxArray definition and uses in computer.pptx
Array definition and uses in computer.pptx
naushigrdcs
Introduction to Array & Structure & Basic Algorithms.pptx
Introduction to Array & Structure & Basic Algorithms.pptxIntroduction to Array & Structure & Basic Algorithms.pptx
Introduction to Array & Structure & Basic Algorithms.pptx
MrNikhilMohanShinde
arrays used for data structures and algorithms
arrays used for data structures and algorithmsarrays used for data structures and algorithms
arrays used for data structures and algorithms
dkkamat
PPS SSSSHHEHESHSHEHHEHAKAKHEHE12131415.pdf
PPS SSSSHHEHESHSHEHHEHAKAKHEHE12131415.pdfPPS SSSSHHEHESHSHEHHEHAKAKHEHE12131415.pdf
PPS SSSSHHEHESHSHEHHEHAKAKHEHE12131415.pdf
YashShekhar6
ReviewArrays.ppt
ReviewArrays.pptReviewArrays.ppt
ReviewArrays.ppt
AliAhmad38278
SPL 12 | Multi-dimensional Array in C
SPL 12 | Multi-dimensional Array in CSPL 12 | Multi-dimensional Array in C
SPL 12 | Multi-dimensional Array in C
Mohammad Imam Hossain
Array , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptxArray , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptx
MrNikhilMohanShinde
Lecture 15 - Array
Lecture 15 - ArrayLecture 15 - Array
Lecture 15 - Array
Md. Imran Hossain Showrov
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
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
Rajendran
ARRAYSCPP.pptx
ARRAYSCPP.pptxARRAYSCPP.pptx
ARRAYSCPP.pptx
727822TUCS116MOHANKU
Arrays
ArraysArrays
Arrays
swathi reddy
L10 array
L10 arrayL10 array
L10 array
teach4uin
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
HEMAHEMS5
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
Swarup Boro
javaarray
javaarrayjavaarray
javaarray
Arjun Shanka
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
Dr.Subha Krishna
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
悖忰惆 忰惆
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
rohinitalekar1
Array definition and uses in computer.pptx
Array definition and uses in computer.pptxArray definition and uses in computer.pptx
Array definition and uses in computer.pptx
naushigrdcs
Introduction to Array & Structure & Basic Algorithms.pptx
Introduction to Array & Structure & Basic Algorithms.pptxIntroduction to Array & Structure & Basic Algorithms.pptx
Introduction to Array & Structure & Basic Algorithms.pptx
MrNikhilMohanShinde
arrays used for data structures and algorithms
arrays used for data structures and algorithmsarrays used for data structures and algorithms
arrays used for data structures and algorithms
dkkamat
PPS SSSSHHEHESHSHEHHEHAKAKHEHE12131415.pdf
PPS SSSSHHEHESHSHEHHEHAKAKHEHE12131415.pdfPPS SSSSHHEHESHSHEHHEHAKAKHEHE12131415.pdf
PPS SSSSHHEHESHSHEHHEHAKAKHEHE12131415.pdf
YashShekhar6
SPL 12 | Multi-dimensional Array in C
SPL 12 | Multi-dimensional Array in CSPL 12 | Multi-dimensional Array in C
SPL 12 | Multi-dimensional Array in C
Mohammad Imam Hossain
Array , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptxArray , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptx
MrNikhilMohanShinde
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
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
Rajendran
L10 array
L10 arrayL10 array
L10 array
teach4uin
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
HEMAHEMS5
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
Swarup Boro

Recently uploaded (20)

"Introduction to VLSI Design: Concepts and Applications"
"Introduction to VLSI Design: Concepts and Applications""Introduction to VLSI Design: Concepts and Applications"
"Introduction to VLSI Design: Concepts and Applications"
GtxDriver
CNC Technology Unit-5 for IV Year 24-25 MECH
CNC Technology Unit-5 for IV Year 24-25 MECHCNC Technology Unit-5 for IV Year 24-25 MECH
CNC Technology Unit-5 for IV Year 24-25 MECH
C Sai Kiran
windrose1.ppt for seminar of civil .pptx
windrose1.ppt for seminar of civil .pptxwindrose1.ppt for seminar of civil .pptx
windrose1.ppt for seminar of civil .pptx
nukeshpandey5678
Kamal 2, new features and practical examples
Kamal 2, new features and practical examplesKamal 2, new features and practical examples
Kamal 2, new features and practical examples
Igor Aleksandrov
he Wright brothers, Orville and Wilbur, invented and flew the first successfu...
he Wright brothers, Orville and Wilbur, invented and flew the first successfu...he Wright brothers, Orville and Wilbur, invented and flew the first successfu...
he Wright brothers, Orville and Wilbur, invented and flew the first successfu...
HardeepZinta2
Water Industry Process Automation & Control Monthly - April 2025
Water Industry Process Automation & Control Monthly - April 2025Water Industry Process Automation & Control Monthly - April 2025
Water Industry Process Automation & Control Monthly - April 2025
Water Industry Process Automation & Control
Airport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANE
Airport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANEAirport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANE
Airport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANE
Priyanka Dange
PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...
PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...
PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...
yadavchandan322
applicationof differential equation.pptx
applicationof differential equation.pptxapplicationof differential equation.pptx
applicationof differential equation.pptx
PPSTUDIES
CNC Technology Unit-1 for IV Year 24-25 MECH
CNC Technology Unit-1 for IV Year 24-25 MECHCNC Technology Unit-1 for IV Year 24-25 MECH
CNC Technology Unit-1 for IV Year 24-25 MECH
C Sai Kiran
Machine Elements in Mechanical Design.pdf
Machine Elements in Mechanical Design.pdfMachine Elements in Mechanical Design.pdf
Machine Elements in Mechanical Design.pdf
SLatorreAndrs
Scalling Rails: The Journey to 200M Notifications
Scalling Rails: The Journey to 200M NotificationsScalling Rails: The Journey to 200M Notifications
Scalling Rails: The Journey to 200M Notifications
Gustavo Araujo
UHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptx
UHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptxUHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptx
UHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptx
ariomthermal2031
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
UHV UNIT-5    IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...UHV UNIT-5    IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
ariomthermal2031
Artificial intelligence and Machine learning in remote sensing and GIS
Artificial intelligence  and Machine learning in remote sensing and GISArtificial intelligence  and Machine learning in remote sensing and GIS
Artificial intelligence and Machine learning in remote sensing and GIS
amirthamm2083
22PCOAM16 ML UNIT 2 NOTES & QB QUESTION WITH ANSWERS
22PCOAM16 ML UNIT 2 NOTES & QB QUESTION WITH ANSWERS22PCOAM16 ML UNIT 2 NOTES & QB QUESTION WITH ANSWERS
22PCOAM16 ML UNIT 2 NOTES & QB QUESTION WITH ANSWERS
Guru Nanak Technical Institutions
02.BigDataAnalytics curso de Legsi (1).pdf
02.BigDataAnalytics curso de Legsi (1).pdf02.BigDataAnalytics curso de Legsi (1).pdf
02.BigDataAnalytics curso de Legsi (1).pdf
ruioliveira1921
Optimize AI Latency & Response Time with LLumo
Optimize AI Latency & Response Time with LLumoOptimize AI Latency & Response Time with LLumo
Optimize AI Latency & Response Time with LLumo
sgupta86
Knowledge-Based Agents in AI: Principles, Components, and Functionality
Knowledge-Based Agents in AI: Principles, Components, and FunctionalityKnowledge-Based Agents in AI: Principles, Components, and Functionality
Knowledge-Based Agents in AI: Principles, Components, and Functionality
Rashmi Bhat
Shallow base metal exploration in northern New Brunswick.pdf
Shallow base metal exploration in northern New Brunswick.pdfShallow base metal exploration in northern New Brunswick.pdf
Shallow base metal exploration in northern New Brunswick.pdf
DUSABEMARIYA
"Introduction to VLSI Design: Concepts and Applications"
"Introduction to VLSI Design: Concepts and Applications""Introduction to VLSI Design: Concepts and Applications"
"Introduction to VLSI Design: Concepts and Applications"
GtxDriver
CNC Technology Unit-5 for IV Year 24-25 MECH
CNC Technology Unit-5 for IV Year 24-25 MECHCNC Technology Unit-5 for IV Year 24-25 MECH
CNC Technology Unit-5 for IV Year 24-25 MECH
C Sai Kiran
windrose1.ppt for seminar of civil .pptx
windrose1.ppt for seminar of civil .pptxwindrose1.ppt for seminar of civil .pptx
windrose1.ppt for seminar of civil .pptx
nukeshpandey5678
Kamal 2, new features and practical examples
Kamal 2, new features and practical examplesKamal 2, new features and practical examples
Kamal 2, new features and practical examples
Igor Aleksandrov
he Wright brothers, Orville and Wilbur, invented and flew the first successfu...
he Wright brothers, Orville and Wilbur, invented and flew the first successfu...he Wright brothers, Orville and Wilbur, invented and flew the first successfu...
he Wright brothers, Orville and Wilbur, invented and flew the first successfu...
HardeepZinta2
Airport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANE
Airport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANEAirport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANE
Airport Components Part1 ppt.pptx-Site layout,RUNWAY,TAXIWAY,TAXILANE
Priyanka Dange
PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...
PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...
PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...
yadavchandan322
applicationof differential equation.pptx
applicationof differential equation.pptxapplicationof differential equation.pptx
applicationof differential equation.pptx
PPSTUDIES
CNC Technology Unit-1 for IV Year 24-25 MECH
CNC Technology Unit-1 for IV Year 24-25 MECHCNC Technology Unit-1 for IV Year 24-25 MECH
CNC Technology Unit-1 for IV Year 24-25 MECH
C Sai Kiran
Machine Elements in Mechanical Design.pdf
Machine Elements in Mechanical Design.pdfMachine Elements in Mechanical Design.pdf
Machine Elements in Mechanical Design.pdf
SLatorreAndrs
Scalling Rails: The Journey to 200M Notifications
Scalling Rails: The Journey to 200M NotificationsScalling Rails: The Journey to 200M Notifications
Scalling Rails: The Journey to 200M Notifications
Gustavo Araujo
UHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptx
UHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptxUHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptx
UHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptx
ariomthermal2031
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
UHV UNIT-5    IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...UHV UNIT-5    IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
ariomthermal2031
Artificial intelligence and Machine learning in remote sensing and GIS
Artificial intelligence  and Machine learning in remote sensing and GISArtificial intelligence  and Machine learning in remote sensing and GIS
Artificial intelligence and Machine learning in remote sensing and GIS
amirthamm2083
02.BigDataAnalytics curso de Legsi (1).pdf
02.BigDataAnalytics curso de Legsi (1).pdf02.BigDataAnalytics curso de Legsi (1).pdf
02.BigDataAnalytics curso de Legsi (1).pdf
ruioliveira1921
Optimize AI Latency & Response Time with LLumo
Optimize AI Latency & Response Time with LLumoOptimize AI Latency & Response Time with LLumo
Optimize AI Latency & Response Time with LLumo
sgupta86
Knowledge-Based Agents in AI: Principles, Components, and Functionality
Knowledge-Based Agents in AI: Principles, Components, and FunctionalityKnowledge-Based Agents in AI: Principles, Components, and Functionality
Knowledge-Based Agents in AI: Principles, Components, and Functionality
Rashmi Bhat
Shallow base metal exploration in northern New Brunswick.pdf
Shallow base metal exploration in northern New Brunswick.pdfShallow base metal exploration in northern New Brunswick.pdf
Shallow base metal exploration in northern New Brunswick.pdf
DUSABEMARIYA

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