he above statement will take 10th element from the array and assign the value to salary variable. Following is an example which will use all the above mentioned three concepts viz. declaration, assignment and accessing arrays:
#include <stdio.h>
int main ()
{
int n[ 10 ]; /* n is an array of 10 integers */
int i,j;
/* initialize elements of array n to 0 /
for ( i = 0; i < 10; i++ )
{
n[ i ] = i + 100; / set element at location i to i + 100 */
}
/* output each array element’s value */
for (j = 0; j < 10; j++ )
{
printf(“Element[%d] = %d\n”, j, n[j] );
}
return 0;
}
When the above code is compiled and executed, it produces the following result:
Element[0] = 100
Element[1] = 101
Element[2] = 102
Element[3] = 103
Element[4] = 104
Element[5] = 105
Element[6] = 106
Element[7] = 107
Element[8] = 108
Element[9] = 109
…
to pass a value in a function … you need to use some formal variables which are in main() function for eg
main()
{
func(int a, int b)
}
int func (int x,int y)
{
so here when the calculation in your self defined function gets over the value of x which is for function only which is considered as ‘a’ variable in main()
gets transferred to a
means…
a=x x value goes to a after calculation
…
b=y;
same thing … now check your program and read a C book again