Comprehensive C Language Notes for Sale
C Language Notes for Sale
User
Well in depth description about c language notes to sell
ChatGPT
Title: Comprehensive C Language Notes for Sale
Introduction:
Our comprehensive C Language notes offer a detailed and in-depth resource for individ...
ARRAY
An array is a collection of similar type of data items and each data item
is called an element of the array. The data type of the elements may be
any valid datatype like char, int or float. The element of array share the
same variable name but each element has different index number known
as subscript.
Ex: lets take an array variable age of size 100 and of type int. The size of
this array variable is 100 so it is capable of storing 100 integer values.
The individual elements of this array are-
Age[0],age[1],age[2],age[3],age[4]………age[98],age[99]
In C the subscript starts from zero, so age [0] is the first element, age[1]
is the second element of array and so on.
Arrays can be single dimensional or multidimensional. The number of
subscript determines the dimension of array.
One Dimensional Array
Declaration of one dimensional Array
Like other simple variables, arrays should also be declared before they
are used in the program. The syntax for declaration of an array is:
Data_type array_name[size];
Here array _name denotes the name of the array and it can be any valid
C identifier, data_type is the data type of the elements of array. The size
of the array specifies the number of elements that can be stored in the
array. Here are some examples of array declarations:
int age[100];
float salary[15];
char grade[20];
Here age is an array of type int,which can store 100 elements of type int.
The array salary is a float type array size of 15, can hold values of type
Page 1 of 15 BCA-I
, Programming In C
float and third one is a character type array of size 20, can hold
characters.
Accessing 1-D Array Elements:
The elements of an array can be accessed by specifying the array name
followed by subscript in brackets. In C , the array subscript start from 0.
Hence if there is an array of size 5, the valid subscript s will be from 0 to
4. The last valid subscript is one less than the size of the array. This valid
subscript is known as the upper bound of the array and 0 is known as the
lower bound of the array.
Ex:
int arr[5]; /*Size of an array is 5 , can hold five integer elements*/
The elements of this array are-
arr[0],arr[1],arr[2],arr[3],arr[4]
Here 0 is the lower bound and 4 is the upper bound of the array arr.
Processing 1 –D Array :
1. Reading values in arr
for(i=0;i<10;i++)
Scanf(“%d”,&arr[i]);
2. Displaying values of arr
for(i=0;i<10;i++)
Printf(“%d”,arr[i]);
Initialization of 1-D array:
Variables can be assigned values during declaration like the following
example.
Int x=7;
Arrays can be initialized in the same manner. However, since an array has
multiple elements, braces are used to denote the entire array of values
and commas are used to separate the individual values assigned to the
elements in the array initialization statements as shown.
a) int A[10]={9,8,7,6,5,4,3,2,1,0};
9 8 7 6 5 4 3 2 1 0 Values stored in the
array elements
Page 2 of 15 BCA-I
, Programming In C
0123456789 index values of array elements
b) double a[5]={3.67,1.21,5.87,7.45,9.12}
Automatic sizing while initializing,the size of a one dimensional
array can be omitted as shown.
int arr[]={3,1,5,7,9};
Here , the C compiler will deduce the size of the array from the
initialization statement.
From above initialization statement , the size of the array is
deducted to be 5.
Two Dimensional Array in C
The two-dimensional array can be defined as an array of arrays. The 2D
array is organized as matrices which can be represented as the collection
of rows and columns. However, 2D arrays are created to implement a
relational database lookalike data structure. It provides ease of holding
the bulk of data at once which can be passed to any number of functions
wherever required.
Declaration of two dimensional Array :
The syntax to declare the 2D array is given below.
data_type array_name [rows][columns];
Consider the following example.
int twodimen [4][3];
Here, 4 is the number of rows, and 3 is the number of columns.
Processing 2-D Array:
Ex: int a[9][5];
1. Reading values in a
for(i=0;i<9;i++)
for(j=0;j<5;j++)
scanf(“%d”,&a[i][j]);
Page 3 of 15 BCA-I
Voordelen van het kopen van samenvattingen bij Stuvia op een rij:
√ Verzekerd van kwaliteit door reviews
Stuvia-klanten hebben meer dan 700.000 samenvattingen beoordeeld. Zo weet je zeker dat je de beste documenten koopt!
Snel en makkelijk kopen
Je betaalt supersnel en eenmalig met iDeal, Bancontact of creditcard voor de samenvatting. Zonder lidmaatschap.
Focus op de essentie
Samenvattingen worden geschreven voor en door anderen. Daarom zijn de samenvattingen altijd betrouwbaar en actueel. Zo kom je snel tot de kern!
Veelgestelde vragen
Wat krijg ik als ik dit document koop?
Je krijgt een PDF, die direct beschikbaar is na je aankoop. Het gekochte document is altijd, overal en oneindig toegankelijk via je profiel.
Tevredenheidsgarantie: hoe werkt dat?
Onze tevredenheidsgarantie zorgt ervoor dat je altijd een studiedocument vindt dat goed bij je past. Je vult een formulier in en onze klantenservice regelt de rest.
Van wie koop ik deze samenvatting?
Stuvia is een marktplaats, je koop dit document dus niet van ons, maar van verkoper kiranrewatkar. Stuvia faciliteert de betaling aan de verkoper.
Zit ik meteen vast aan een abonnement?
Nee, je koopt alleen deze samenvatting voor €8,16. Je zit daarna nergens aan vast.