-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray
More file actions
43 lines (32 loc) · 1.23 KB
/
array
File metadata and controls
43 lines (32 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
============================================================================
Name : array.c
Author :
Version :
Copyright : Your copyright notice
Description : Hello World in C, Ansi-style
============================================================================
*/
//Arrays -- allocate one contiguous block of memory holding declaring multiple of one data type
//name of array used is an address of memory.
//Declaration with Assignment -- declaring 10 doubles
double balance[10] = {1000.0, 2.0, 3.4, 7.0,50.0};
//when using in calculation or assignment below recall always start at 0
//balance[0] = 1000.0 , balance[3] = 7.0, balance[7] = 0, balance[10] = error out of bounds
//Also acceptable because size will be known. Size will be 5 hence --> double balance[5]
double balanceTwo[] = {1000.0, 2.0, 3.4, 7.0,50.0};
//code example
#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;
}