Arrays in C
. Define an array?
Arrays are defined as collection of similar data elements stored at contiguous location.
Note: 1. Contiguous : next in sequence
2. Homogeneous: Similar
same kind of people or thing
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Main memory is divided into three sections
- Heap
- Stack
- Code Section
Variables are created inside the stack.
Variables will be directly accessible to the main function.
---------------------------------------------------------------------------------------------------------
How to declare an array and access element of the array?
#include<stdio.h>
#include<conio.h>
int main()
{
int a[5]={4,6,7};
int i;
for(i=0;i<5;i++)
{
printf(" a[%d]=%d",i,a[i]);
}
return 0;
}
Code pics:
output:
online compile link
https://www.onlinegdb.com/online_c_compiler
Comments
Post a Comment