0% found this document useful (0 votes)
5 views10 pages

Understanding Arrays in Programming

An array is a collection of similar elements stored in contiguous memory locations that can be accessed using an index. It allows storing multiple values of the same data type. Elements in an array are accessed using the index operator [] with indexes starting from 0. Common operations on arrays include initializing values, scanning or printing elements using loops, sorting elements, and reversing elements or the entire array. Arrays can also be treated as pointers where the array name represents the base address.

Uploaded by

mugger000
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views10 pages

Understanding Arrays in Programming

An array is a collection of similar elements stored in contiguous memory locations that can be accessed using an index. It allows storing multiple values of the same data type. Elements in an array are accessed using the index operator [] with indexes starting from 0. Common operations on arrays include initializing values, scanning or printing elements using loops, sorting elements, and reversing elements or the entire array. Arrays can also be treated as pointers where the array name represents the base address.

Uploaded by

mugger000
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Reality. Reinvented.

● it is one of the derived datatype.


● Array is a collection of similar elements which are in a
contiguous memory location.
● when no: of data increases it’s difficult to manage.

Syntax:
datatype var_name[ no ele ];

eg: int arr[5];


char chr[20];
● for accessing elements of array we need to use [ ]
index operator
● index start with ‘0’ .

● initial value of array is garbage values.


scan and print array:
● instead of printing each elements we can use loop
concepts.
scaning :
for(int i=0; i<ele; i++)
{
// scanf(“%d”,&a[i]);

printf(“%d”,a[i]);
}
initialization of data:
● int a[5];
● int a[ ];
● int a[5] = 10,20,30,40,50;
● int a[5] = 10,20;
● int a[5] = 10,20,30,40,50,60,70;
● int a[ ] = 10,20,30,40,50;
programs:

1. WAP to reverse print an array?


2. WAP to reverse element of array?
3. WAP to check palindrom number are present or not in
a [Link] present print the number
4. WAP to find largest in an array
sorting of an array:

● Bubble sort:
○ compare with ‘0’th and ‘i’ th index element.

● selection sort:
○ fix one index and other index values compare with
others.
● Array and pointer:

○ Array name represents base address of array


○ a+i and &a+i
○ Array treated as constant pointer.
int *const p;
p++; →error

● copying an array:
● character and integer pointer on array
THANK YOU
Contact:
Fasil KV
9497042007
fasil@[Link]
[Link]

You might also like