100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
New! Comprehensive C Language Notes 2023 $8.39   Add to cart

Interview

New! Comprehensive C Language Notes 2023

 1 view  0 purchase
  • Course
  • Institution

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...

[Show more]

Preview 3 out of 15  pages

  • May 22, 2023
  • 15
  • 2022/2023
  • Interview
  • Unknown
  • Unknown
  • Secondary school
  • 1
avatar-seller
Programming In C




UNIT-IV


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

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller kiranrewatkar. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $8.39. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

83750 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$8.39
  • (0)
  Add to cart