C language has an integer array a with 10 elements. All elements in the array must be output.
There is an integer array a with 10 elements. All elements in the array must be output.
Solution: There are three methods to reference the values of each element in the array: 1. subscript method, such as a [3]; 2. calculate the address of the array element using the array name to find the element value.
3. Use Pointer variables to point to array elements.
// Use Pointer variables to point to array elements # include
Int main () {int a [10]; int I; int * p; printf ("Enter 10 integers \ n"); for (I = 0; I <10; I ++) scanf ("% d", & a [I]); for (p = a; p <(a + 10); p ++) printf ("% 2d", * p); printf ("% \ n"); return 0;} // calculate the array element address using the array name # include
Int main () {int a [10]; int I; printf ("Enter 10 integers \ n"); for (I = 0; I <10; I ++) scanf ("% d", & a [I]); for (I = 0; I <10; I ++) printf ("% 2d ", * (a + I); printf ("% \ n"); return 0;} // subscript method # include
Int main () {int a [10]; int I; printf ("Enter 10 integers \ n"); for (I = 0; I <10; I ++) scanf ("% d", & a [I]); for (I = 0; I <10; I ++) printf ("% 2d ", a [I]); printf ("% \ n"); return 0 ;}