CS 105: C++
Quiz 5 Requirements
C: Chapter 5

  1. Know how to declare a simple pointer (e.g., a pointer to an int), and know how to set it to point to something.

  2. Know how to dereference a pointer to read or change the value it points to.

  3. Understand the basics of pointer arithmetic.  What does it mean to add or subtract a number to or from a pointer?  Be able to use pointer arithmetic instead of square brackets to access the elements of an array.  Are the numbers used in pointer arithmetic related at all to the size the individual elements in an array?

  4. Know how to declare, initialize, and access a simple two-dimensional array (e.g., a 3 by 5 array of ints).

  5. Understand the basics of argc and argv.  What are each of them set to when your program is run from the command line? What is argv[0]?  If a program takes two arguments, is its argc 2, or is it something else?

  6.  Although the syntax can get very awkward, and their use is relatively rare, at least be able to recognize a simple pointer to a function if you see one.

  7. Although they are identical to the compiler, which of the following pointer declarations is typically used in the reading?

      int *ip;
      int* ip;

    Why is that?  Here's a hint: Which of the following declares two pointers to int?

      int *ip1, *ip2;
      int* ip1, ip2;

  8. Understand exactly how to use pointers to "work around" the fact that all functions in C are pass by value.  For example, the code below seems to be trying to add 5 to x, but it fails due to pass-by-value.  How could you change add_5 and its call from main (without making add_5 return a value) to fix this?

      void add_5(int n)
      {
        n = n + 5;
      }

      main()
      {
        int x = 2;

        add_5(x);
      }



Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.