CS16, 10S, H02 (due Fri Lecture 04.02) Oualline, Chapters 3, 4--Style, C basics—Total points: ?
Online version: http://www.cs.ucsb.edu/~pconrad/cs16/10S/homework/H02 (printable PDF)

Accepted: on paper, in lecture (9am, 10am, 11am or noon) on Friday, 04/02 in Chem 1171

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 (3 pts)  ______________@umail.ucsb.edu

Lab Section (4 pts) Circle one:         9am        10am          11am            noon        crashing      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 FRIDAY 04/02
It may ONLY be turned in IN LECTURE ON FRIDAY 04/02

The only other time/place this lab will be accepted is in person, at your instructor's office hours within one week of 04/02 , or the day you add the class on GOLD, whichever is later, in accordance with the homework policies outlined on the course syllabus. Make this appointment within 48 hours of 04/02, or when you add the course.

Please obtain the official textbook for this course by Delores Etter. I will assign homework from that book on Friday, and it will be due on Monday 04/05. Here is an excerpt from a memo from the bookstore regarding availability of textbooks:

...
I wanted to send out a reminder regarding what to say to students who complain that they can't get the book....if you would forward this email to your faculty it would be much appreciated and hopefully eliminate some anxiety for students and faculty.

TELL THE STUDENTS TO COME TALK TO US IN THE TEXTBOOK DEPARTMENT. We will make sure they get a book. If we are out, we can get more copies in approximately three to five business days.

If students don't talk to us we have no way of knowing somebody wants a book. We base our reordering on need. Students shop in so many different places these days we cannot predict how many will want to shop here. Freight is hugely expensive, as is the labor involved in bringing books in that we might not be able to sell. Therefore, we need to hear from our students if they want something...

Best wishes,
Cynthia Ellestad, Course Materials Department Manager, UCSB Bookstore

For now, the reading assignments are chapters from an online textbook—Practical C Programming by Steve Oualline. Links to material in this book appear below.

Once you've read Chapter 5, write answers to the questions on the reverse side of this sheet (use the PDF link to print a copy of this if you weren't in class).

Even though this book is a bit "dated"—for example, the advice in section about 5.8 about float vs. double is the opposite of what I told you in class*—there is still lots of good information in this book. And is has the advantage of being free, and available to you while we wait for everyone to get their textbooks.

(*Regarding float and double—my advice is always use double unless you have a specific reason to prefer float. The reason the conventional wisdom has changed: memory is cheaper and processor speeds are faster than they once were.)

To link directly to this book, use these links: (on campus) (off campus)

Please turn over for questions to answer


Continued from other side

  1. In Chapter 5, the author describes how to declare arrays.

    1. (5 pts) How would you write a line of C code that declares an array to hold 10 integers, each representing a students exam score?



    2. (5 pts) What would be the highest index (subscript) used to access an item in this array—i.e. the highest number you could put in [ ] to pull out a single element of this array?


  2. (10 pts) Let's suppose you've just read through Chapter 5 of the online reading assignment. (If you haven't yet, please go ahead and do so for real, before answering this question.)

    Your friend has also read through the section, but your friend isn't quite getting it. Your friend says: I'm still not sure what an array is. I know what a variable is, but I'm not clear on this idea of an array.

    Can you explain it to me in plain english?

    How do you answer your friend?

    (By the way, this quesiton would be a very typical "Phill Conrad-style exam question", so when you are studying for exams in this course, be sure to try to ask yourself questions like this. You might like to get together with a friend and ask each other questions like this to practice.)







  3. According to the author, strings in C are "just character arrays with a few restrictions."

    1. (5 pts) What is the restriction that the author mentions about the ends of strings in C?



    2. (5 pts) The author mentions that to copy one string to another, we can't use an assignment statement—we have to use a special "string copying function" instead. What is the name of that function?




  4. Read what the author has to say about variable length strings in C—including the string that holds the name "Sam" that is mentioned in the reading. (There is something specific about strings in C that is different from string in Java, Python, and many other languages.)

    Then answer these questions.

    1. (5 pts) Which of the following would be the correct way to declare a string variable for "state" that could hold two letter state abbreviations as a C-string? (Choose one)


      char [] state;

      char state [];

      char state[2];

      char state[3];

      char state[4];


    2. (5 pts) Briefly explain your choice.




End of H02