SlideShare a Scribd company logo
1 of 27
Arrays
In C Language
Contents
I. Introduction
 Declaring and creating Arrays
 Accessing array elements
 Array: input & output
II. One- dimensional Arrays
III. Declaration of One- dimensional Arrays
IV. Initialization of One- dimensional Arrays
V. Two- dimensional Arrays
VI. Initialization of Two- dimensional Arrays
VII. Multi-dimensional Arrays
VIII. Dynamic Arrays
IX. Array examples
INTRODUCTION
What is An Array?
 An array is a fixed-size sequenced collection of elements of the same
data type.
 It is simply a grouping of like-type data. In its simplest form, an array
can be used to represent a list of numbers, or a list of names.
 Some examples where the concept of array can be used are as under:
 List of temperatures recorded every hour in a day, or a month, or a
year.
 List of employees in an organization.
 List of products and their cost sold by a store.
 Test scores of a class of students.
 List of customers and their telephone numbers. Etc.
0 1 2 3 4 Element
index
Element of an array
Array of 5
elements
 An Array provides a convenient structure forrepresenting
data hence it is classified as one of the Data Structure In C.
 Example:
income[10]
 The above example represents the income of employees.
Individual values are called elements While the complete set
of values is referred to as an array. In above example there
can be maximum 10 elements.
 An Array is a derived data type
 Based on the basis of dimensions there are three types of
array :
1. One - dimensional Arrays
2. Two - dimensional Arrays
3. Multi - dimensional Arrays
Declaring & Creating Arrays
Declaring Arrays
 Declaration defines the type of the elements
 Square brackets [ ] indicate “Array size"
 Examples:
(Where s.o.a is size of array)
int array[s.o.a];
Creating and Initializing Arrays
 Creating and initializing can be done together:
Int myIntArray[5] = {1, 2, 3, 4, 5};
myIntArray
managed heap
(dynamic memory)
0 1 2 3 4
… … … … …
Accessing Array Elements
READ AND MODIFY ELEMENTS BY INDEX
How to Access Array Element?
 Array elements are accessed using the square brackets operator []
(indexer)
› Array indexer takes element’s index as parameter
› The first element has index 0
› The last element has index Length-1
 Array elements can be retrieved and changed by the [ ] operator
Arrays: Input and Output
Reading and Printing Arrays on the Console
Reading Arrays
 Ex. Int array[5];
Scanf(“%d”,&array[5]);
-------------------------------------------------
-------------------------------------------------
Printing Arrays
printf(“a[5]=%d”,array[5]);
-------------------------------------------------
-------------------------------------------------
One - Dimensional Arrays
 A list of item can be given one variable name using
only one subscript and such a variable is called a
single subscripted variable or One- dimensional array.
 It can be expressed as :
x[0], x[1], x[2], x[3], x[4]……..x[n]
C performs no bound checking and, therefore, care
should be exercised to ensure that the array indices
are within the declared limits.
Declaration of One-Dimensional Array
 Syntax:
 Data type can be int, float, char etc.
 Ex.
> int chat[10];
> char pr[50];
 Array of char data type is called STRING.
 When compiler sees a char String, it terminates it with
an additional null character. so string array holds the null
char ‘0’.we must allow 1 extra element space for the null
terminator.
data type variable_name[s.o.a];
Initialization of one Dimensional Array
 An array can be initialized at either of the following two
stages:
 At compile time
 At run time
• At compile time
 Syntax::
datatype array name[S.O.A]={list of value};
Ex:: int array[5]={1,2,3,4,5};
 If we have more initializers than the declared size, the
compiler will produce an error. That is illegal in C.
 Ex:: int number[3]={1,2,3,4,5};
• Run Time Initialization
 An array can be explicitly initialized at run time. This
approach is usually applied for initialization large arrrays.
 Ex::
 ---------------------------------------------------------------
 ---------------------------------------------------------------
 For (i=0; i<5; i++)
 {
 sum[i]=I;
 }
 ---------------------------------------------------------------
 ---------------------------------------------------------------
.
 We can also use a read function such as scanf to initialize array.
 Ex::
 Int x[3];
 Scanf (“%d %d %d ,&x[0], &x[0], &x[0]”);
 Will intialize array elements with the value entered
through the keyboard.
Two Dimensional Array
 If we have store the value as table then we have to use 2-D
array.
 Ex:-
 C allow s us to define such tables of items by using 2-D
arrays.
 Syntax::
 Type array name[raw size][column size];
Hear the first index contains row size, second index
contains column size.
i-1 i-2 i-3
1. 10 20 30
2. 20 10 13
Initialization of Two Dimensional Array
 Like 1-d array, 2-d array may be initialized by following
their declaration with a list of initial values enclosed in
braces.
 Ex::
 Int table[2][3]={0,0,0,1,1,1};
 Int table[2][3]={ {0,0,0} ,{1,1,1} };
 Hear the first index saw raw size, second Index saw
column size.
Multi Dimensional Array
 C allows arrays of three or more dimensions. The exact limit is determined
by the compiler .
 The general form of a multi –dimensional array is…..
 Type array name[x1][x2][x3][x4]……..[xn];
 Where x1 x1 is size of array.
 ANSI C does not specify any limit for array dimension. However ,
most compiler permit seven to ten dimension . Some allow even
more.
Dynamic Arrays
 We created array at run time, so we can not modify it at run time so theyare
called static array. This approach works fine as long as we know exactly
what our data requirement are..
 In C it is possible to allocate memory to arrays at run time , which knownas
dynamic memory allocation and the array called dynamic array.
 Dynamic array are created using what are known as pointer variables and
memory management function malloc, calloc, realloc, which are in
<stdio.h>
Some Examples of Array
 Ex: Write a program to print first 10 number.
::
#include<stdio.h>
void main()
{
int i, pr[10];
for (i=0;i<10;i++)
{
r[i]=i + 1;
printf("%d",r[i]);
printf(” n”);
}
}
:: output::
1
2
3
4
5
6
7
8
9
10
 Write a program to read and display 3x3 matrix.
# i n c l u d e < s t d i o . h >
v oi d m a i n ( )
{
i n t i , j , a [ 3 ] [ 3 ] ;
o f 3 x 3 M a t r i x :  n ” ) ;
” , i , j );
p r i n t f ( “ E n t e r t h e e l e m e n t s
f o r ( i = 0 ; i < 3 ; i + + )
f o r ( j = 0 ; j < 3 ; j + + )
{
p r i n t f ( “ a [ % d ] [ % d ] =
s c a n f (“% d ” , a [ i ] [ j ] ) ;
}
i n 3 x 3 m a t r i x a r e :  n ” ) ;
p r i n t f ( “ T h e v a r i o u s e l e m e n t s
f o r ( i = 0 ; i < 3 ; i + + )
{
p r i n t f (“  n  t  t ”);
f o r ( j = 0 ; j < 3 ; j + + )
p r i n t f (“%d  t ” , a [ i ] [ j ] ) ;
}}
:: output ::
E n t e r t h e e l e m e n t s o f t h e 3 x 3 m a t r i x :
a [ 0 ] [ 0 ] = 1
a [ 0 ] [ 1 ] = 2
a[ 0] [ 2] = 3
a [ 1 ] [ 0 ] = 4
a [ 1 ] [ 1 ] = 5
a [ 1 ] [ 2 ] = 6
a [ 2 ] [ 0 ] = 7
a [ 2 ] [ 1 ] = 8
a[ 2] [ 2] = 9
T h e v a r i o u s e l e m e n t s o f t h e 3 X 3 m a t r i x :
1 2 3
4 5 6
7 8 9
End of Presentation

More Related Content

What's hot (20)

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
 
C arrays
C arraysC arrays
C arrays
 
Array in c
Array in cArray in c
Array in c
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Arrays C#
Arrays C#Arrays C#
Arrays C#
 
2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional Arrays
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
 
Array in-c
Array in-cArray in-c
Array in-c
 
Array in c++
Array in c++Array in c++
Array in c++
 
Programming in c arrays
Programming in c   arraysProgramming in c   arrays
Programming in c arrays
 
Arrays In C
Arrays In CArrays In C
Arrays In C
 
Arrays
ArraysArrays
Arrays
 
Array and string
Array and stringArray and string
Array and string
 
Arrays
ArraysArrays
Arrays
 
Arrays in C
Arrays in CArrays in C
Arrays in C
 

Similar to Arrays basics

Similar to Arrays basics (20)

Abir ppt3
Abir ppt3Abir ppt3
Abir ppt3
 
Arrays
ArraysArrays
Arrays
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
Arrays
ArraysArrays
Arrays
 
Unit 3
Unit 3 Unit 3
Unit 3
 
Array and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdfArray and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdf
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
Unit 3
Unit 3 Unit 3
Unit 3
 
Array
ArrayArray
Array
 
Array.pptx
Array.pptxArray.pptx
Array.pptx
 
Array
ArrayArray
Array
 
CHAPTER 5
CHAPTER 5CHAPTER 5
CHAPTER 5
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
 
COM1407: Arrays
COM1407: ArraysCOM1407: Arrays
COM1407: Arrays
 
02 arrays
02 arrays02 arrays
02 arrays
 
Array in C full basic explanation
Array in C full basic explanationArray in C full basic explanation
Array in C full basic explanation
 
Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and strings
 
Arrays
ArraysArrays
Arrays
 
Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in C
 

Recently uploaded

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 

Recently uploaded (20)

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 

Arrays basics

  • 2. Contents I. Introduction  Declaring and creating Arrays  Accessing array elements  Array: input & output II. One- dimensional Arrays III. Declaration of One- dimensional Arrays IV. Initialization of One- dimensional Arrays V. Two- dimensional Arrays VI. Initialization of Two- dimensional Arrays VII. Multi-dimensional Arrays VIII. Dynamic Arrays IX. Array examples
  • 4. What is An Array?  An array is a fixed-size sequenced collection of elements of the same data type.  It is simply a grouping of like-type data. In its simplest form, an array can be used to represent a list of numbers, or a list of names.  Some examples where the concept of array can be used are as under:  List of temperatures recorded every hour in a day, or a month, or a year.  List of employees in an organization.  List of products and their cost sold by a store.  Test scores of a class of students.  List of customers and their telephone numbers. Etc.
  • 5. 0 1 2 3 4 Element index Element of an array Array of 5 elements
  • 6.  An Array provides a convenient structure forrepresenting data hence it is classified as one of the Data Structure In C.  Example: income[10]  The above example represents the income of employees. Individual values are called elements While the complete set of values is referred to as an array. In above example there can be maximum 10 elements.  An Array is a derived data type  Based on the basis of dimensions there are three types of array : 1. One - dimensional Arrays 2. Two - dimensional Arrays 3. Multi - dimensional Arrays
  • 8. Declaring Arrays  Declaration defines the type of the elements  Square brackets [ ] indicate “Array size"  Examples: (Where s.o.a is size of array) int array[s.o.a];
  • 9. Creating and Initializing Arrays  Creating and initializing can be done together: Int myIntArray[5] = {1, 2, 3, 4, 5}; myIntArray managed heap (dynamic memory) 0 1 2 3 4 … … … … …
  • 10. Accessing Array Elements READ AND MODIFY ELEMENTS BY INDEX
  • 11. How to Access Array Element?  Array elements are accessed using the square brackets operator [] (indexer) › Array indexer takes element’s index as parameter › The first element has index 0 › The last element has index Length-1  Array elements can be retrieved and changed by the [ ] operator
  • 12. Arrays: Input and Output Reading and Printing Arrays on the Console
  • 13. Reading Arrays  Ex. Int array[5]; Scanf(“%d”,&array[5]); ------------------------------------------------- ------------------------------------------------- Printing Arrays printf(“a[5]=%d”,array[5]); ------------------------------------------------- -------------------------------------------------
  • 14. One - Dimensional Arrays  A list of item can be given one variable name using only one subscript and such a variable is called a single subscripted variable or One- dimensional array.  It can be expressed as : x[0], x[1], x[2], x[3], x[4]……..x[n] C performs no bound checking and, therefore, care should be exercised to ensure that the array indices are within the declared limits.
  • 15. Declaration of One-Dimensional Array  Syntax:  Data type can be int, float, char etc.  Ex. > int chat[10]; > char pr[50];  Array of char data type is called STRING.  When compiler sees a char String, it terminates it with an additional null character. so string array holds the null char ‘0’.we must allow 1 extra element space for the null terminator. data type variable_name[s.o.a];
  • 16. Initialization of one Dimensional Array  An array can be initialized at either of the following two stages:  At compile time  At run time • At compile time  Syntax:: datatype array name[S.O.A]={list of value}; Ex:: int array[5]={1,2,3,4,5};  If we have more initializers than the declared size, the compiler will produce an error. That is illegal in C.  Ex:: int number[3]={1,2,3,4,5}; • Run Time Initialization  An array can be explicitly initialized at run time. This approach is usually applied for initialization large arrrays.
  • 17.  Ex::  ---------------------------------------------------------------  ---------------------------------------------------------------  For (i=0; i<5; i++)  {  sum[i]=I;  }  ---------------------------------------------------------------  --------------------------------------------------------------- .  We can also use a read function such as scanf to initialize array.  Ex::  Int x[3];  Scanf (“%d %d %d ,&x[0], &x[0], &x[0]”);  Will intialize array elements with the value entered through the keyboard.
  • 18. Two Dimensional Array  If we have store the value as table then we have to use 2-D array.  Ex:-  C allow s us to define such tables of items by using 2-D arrays.  Syntax::  Type array name[raw size][column size]; Hear the first index contains row size, second index contains column size. i-1 i-2 i-3 1. 10 20 30 2. 20 10 13
  • 19. Initialization of Two Dimensional Array  Like 1-d array, 2-d array may be initialized by following their declaration with a list of initial values enclosed in braces.  Ex::  Int table[2][3]={0,0,0,1,1,1};  Int table[2][3]={ {0,0,0} ,{1,1,1} };  Hear the first index saw raw size, second Index saw column size.
  • 20. Multi Dimensional Array  C allows arrays of three or more dimensions. The exact limit is determined by the compiler .  The general form of a multi –dimensional array is…..  Type array name[x1][x2][x3][x4]……..[xn];  Where x1 x1 is size of array.  ANSI C does not specify any limit for array dimension. However , most compiler permit seven to ten dimension . Some allow even more.
  • 21. Dynamic Arrays  We created array at run time, so we can not modify it at run time so theyare called static array. This approach works fine as long as we know exactly what our data requirement are..  In C it is possible to allocate memory to arrays at run time , which knownas dynamic memory allocation and the array called dynamic array.  Dynamic array are created using what are known as pointer variables and memory management function malloc, calloc, realloc, which are in <stdio.h>
  • 23.  Ex: Write a program to print first 10 number. :: #include<stdio.h> void main() { int i, pr[10]; for (i=0;i<10;i++) { r[i]=i + 1; printf("%d",r[i]); printf(” n”); } }
  • 25.  Write a program to read and display 3x3 matrix. # i n c l u d e < s t d i o . h > v oi d m a i n ( ) { i n t i , j , a [ 3 ] [ 3 ] ; o f 3 x 3 M a t r i x : n ” ) ; ” , i , j ); p r i n t f ( “ E n t e r t h e e l e m e n t s f o r ( i = 0 ; i < 3 ; i + + ) f o r ( j = 0 ; j < 3 ; j + + ) { p r i n t f ( “ a [ % d ] [ % d ] = s c a n f (“% d ” , a [ i ] [ j ] ) ; } i n 3 x 3 m a t r i x a r e : n ” ) ; p r i n t f ( “ T h e v a r i o u s e l e m e n t s f o r ( i = 0 ; i < 3 ; i + + ) { p r i n t f (“ n t t ”); f o r ( j = 0 ; j < 3 ; j + + ) p r i n t f (“%d t ” , a [ i ] [ j ] ) ; }}
  • 26. :: output :: E n t e r t h e e l e m e n t s o f t h e 3 x 3 m a t r i x : a [ 0 ] [ 0 ] = 1 a [ 0 ] [ 1 ] = 2 a[ 0] [ 2] = 3 a [ 1 ] [ 0 ] = 4 a [ 1 ] [ 1 ] = 5 a [ 1 ] [ 2 ] = 6 a [ 2 ] [ 0 ] = 7 a [ 2 ] [ 1 ] = 8 a[ 2] [ 2] = 9 T h e v a r i o u s e l e m e n t s o f t h e 3 X 3 m a t r i x : 1 2 3 4 5 6 7 8 9