Another array example
//Find
the lowest number in the array num[10]
main()
{
int
num[10]={4,9,11,2,13,77,8,19,21,1};
int min,
i;
min =
num[0];
for (i=1; i<10;
i++) {
if (num[i]
< min)
min =
num[i];
}
printf(“The
minimum is %d”, min);
}
Array
example
/* which
type of integer is valid in array declaration*/
#include <stdio.h>
int main(void)
{
int
x[5]; /* x[5] is array initialization /
x[0]=23; /* valid */
x[2.3]=5; /* invalid: index is not an int */
return
0;
}
Examples
int x
[5] = { 1,2,3,4,5 }; size 10 bytes
creates array with elements 0-4
values 1-5
int x
[5] = {4,3}; size 10 bytes
creates array with elements 0-4
values 4,3,0,0,0
int x
[ ] = {1,2,3}; size 6 bytes
creates array with elements 0-2
values 1,2,3
char
c[4] = {‘M’, ‘o’ , ‘o’ }; size 4 bytes
creates array with elements 0-3
values M o o NULL
No comments:
Post a Comment