Programming Example
Array limit value and an array element address are printed in this program
Array limit value and an array element address are printed in this program
// in the following program, we can see how an array limit
// value and an array element address are printed
#include<stdio.h>
void printarray(int a[]);
void main()
{
int a[15];
int i;
for( i = 0; i<15; i++)
{
a[i] = i;
}
printarray(a);
printdetails(a);
}
void printarray(int a[])
{
int i;
for( i = 0; i<15; i++)
{
printf("Value in the array %d\n",a[i]);
}
}
printdetails(int a[])
{
int i;
for( i = 0; i<15; i++)
{
printf("Value in the array %d and the address is %u\n",a[i],&a[i]);
}
}
Value in the array 0 Value in the array 1 Value in the array 2 Value in the array 3 Value in the array 4 Value in the array 5 Value in the array 6 Value in the array 7 Value in the array 8 Value in the array 9 Value in the array 10 Value in the array 11 Value in the array 12 Value in the array 13 Value in the array 14 Value in the array 0 and the address is 37813988 Value in the array 1 and the address is 37813992 Value in the array 2 and the address is 37813996 Value in the array 3 and the address is 37814000 Value in the array 4 and the address is 37814004 Value in the array 5 and the address is 37814008 Value in the array 6 and the address is 37814012 Value in the array 7 and the address is 37814016 Value in the array 8 and the address is 37814020 Value in the array 9 and the address is 37814024 Value in the array 10 and the address is 37814028 Value in the array 11 and the address is 37814032 Value in the array 12 and the address is 37814036
First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.