CS16, 10W, UCSB

H08: (Array Initialization, Etter, Section 5.1) Total points: ? (printable PDF)

Available online at: http://www.cs.ucsb.edu/~pconrad/cs16/10W/homework/H08

Accepted: on paper, in Lecture (11am Thursday Feb 4th)

Late Policy: No email submission allowed—and don't "slip it under my door". If you need to make it up, you must do so during office hours, or make an appointment to see me, and you must request this appointment within 48 hours of when the assignment was originally due.

Personal Day/Sick Day policy: Everyone is permitted one "personal day/sick day" when you get to make up a missed homework assignment for free during office hours or via appointment. After that, you may not make up the homework assignment—you can only earn back the points through extra credit opportunities.       
(For more details, see the syllabus and the homework policy)


Name: (3 pts)___________________________  UMail address (4 pts)  ______________@umail.ucsb.edu

Lab Section (3 pts) Circle one:         3pm       4pm         5pm           unknown

(Note: For now, circle the lab section you are registered for on GOLD. If you need to request attendance at a different lab section because of an ACTUAL SCHEDULE CONFLICT, please email pconrad@cs.ucsb.edu with details)


This assignment is due IN Lecture on Thursday.
It may ONLY be turned in during Lecture on Thursday.
Do NOT turn it in early to your TA on Tuesday in lecture,
or late to your TA in Lab on Thursday .

Name of your pair programming partner(s), if you work together:


Read Section 5.1 in your Etter textbook. Then answer these questions:


  1. Here are several different definitions of the function doIt()—doIt1(), doIt2, etc.
    In each case, indicate what would be printed when the function is called.

    1. (10 pts)

      void doIt1()
      {
      int a[] = {30,40,50};
      printf("%d\n",a[2]);
      }

    2. (10 pts)

      void doIt2()
      {
      int a[5] = {0};
      printf("%d\n",a[2]);
      }

    3. (10 pts)

      void doIt3()
      {
      int a[5] = {1};
      printf("%d\n",a[2]);
      }

    4. (10 pts)

      void doIt4()
      {
      int a[5];
      int i;
      for (i=0; i<5; i++)
      a[i] = (i+1)*2;
      printf("%d\n",a[2]);
      }


      That's all this time—nothing on the other side!


End of H08