#Meta-Wlp: #Macro: TITLE wlp: Learn C (IV) p. 10 #Eval: $TITLE$ #Macro: PAGE bb4-10

Yes, it is the same program.

In C, a[i] is exactly the same as *(a+i).

Int-star is a reference to an integer. In the case of passing arrays to functions, it is a reference to a sequence of integers. By using *(a+i) or a[i] we can get the i-th integer in the sequence, counting from zero as the first in the sequence.

To emphasize this intended meaning, we could say int z[], an array of unspecified dimension, rather than int * z, in the function count_backwards.

Exercise: Explain how this program works.

#include<stdio.h>

int count_backwards( int z[], int ip[] ) {
   int i = 0 ;
   while (z!=(ip+i)) printf("%d, ", ip[i--] ) ;
   printf("%d\n",ip[i]) ;
}

int main(){
  int my_count[3] ;
  my_count[0] = 0 ;
  my_count[1] = 1 ;
  my_count[2] = 2 ;
  count_backwards( my_count, my_count+2 ) ;
}
Exercises
  1. Explain how the above program works.
  2. Write a function which is passed a string and capitalizes only the vowels of the string.
  3. Write a function taking an integer array and an integer saying how many elements are in the array, and it places the smallest element in the array in the zeroth location of the array.
  4. Write a function which copies all the characters from one characters array to another. Assume that the source character array has an end of string marker 0 (it is a string). Here's an outline:
        #include
        int copy_characters( char s[], char t[] ) {
          /* you do the work */
        }
        int main() {
           char * s ;
           char t[16] ; /* 15 characters + end-of-string marker */
           s = "You do the work" ;
           copy_characters( s, t ) ;
        }
    

Learn C Introduction