Â
What are 'Arrays' ?
An Array is known as the collection of Similar data types.
An Array is actually a data structure which consists of a group of elements of same type.
Arrays store same type of elements in consecutive memory location one after another.
Examples :-Â
Suppose there is an array which consists of 5 Elements of integer type let's say the elements are 4,6,2,7,9.
So, if in the above array the address of the memory location of the element 4 is 'a123480' then the address of the memory location of the next element 6 will be 'a123481' and that of the next element i.e. 2 will be 'a123482' and further elements will be followed.
array element           address
4Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 'a123480'
6Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 'a123481'
2Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 'a123482'
7Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 'a123483'
9Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 'a123484'
Now let's dig into how to declare and create an array in C programming language:Â
Syntax:
Now Let's see an example of Array in C:
#include <stdio.h>
int main()
{
int n;
printf("Enter the size of Array\n");
scanf("%d", &n);
//declaring array
int arr[n];
// loop to take array elements from the user
printf("Enter the Elements of Array\n");
for (int i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
}
// printing the array elements
printf("\nArray elements you inputed are :- \n");
for (int i = 0; i < n; i++)
{
printf("%d", arr[i]);
printf("\n");
}
return 0;
}
Output For C
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP