Previous: 9.7 Summary
Up: 9.1 Two Dimensional Arrays
Next: 9.9 Problems
Previous Page: 9.7 Summary
Next Page: 9.9 Problems

9.8 Exercises

Given the following declaration:

int x[10][20];

Explain what each of the following represent:

  1. x

  2. x + i

  3. *(x + i)

  4. *(x + i) + j

  5. *(*(x + i) + j)

  6. x[0]

  7. x[i]

  8. x[i] + j

  9. *(x[i] + j)

    Find and correct errors if any. What does the program do in each case?

  10. main()
    {    int x[5][10];
    

    init(x[][]); }

    void init(int a[][]) { int i, j;

    for (i = 0; i < 10; i++) for (j = 0; j < 5; j++) a[i][j] = 0; }

  11. main()
    {    int x[5][10];
    

    init(x[][]); }

    void init(int *a) { int i, j;

    for (i = 0; i < 10; i++) for (j = 0; j < 5; j++) { *a = 0; a++; }

  12. main()
    {    char s[5][100];
    

    read_strings(s); print_strings(s); }

    read_strings(char s[][100]) { for (i = 0; i < 5; i++) { gets(*s); s++; } }

    print_strings(char s[][100]) { while (*s) { puts(s); s++; } }

tep@wiliki.eng.hawaii.edu
Wed Aug 17 09:20:12 HST 1994