{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

PracticeQuiz0-2011

PracticeQuiz0-2011 - Practice Quiz 0 CS50 Fall 2011...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Practice Quiz 0 CS50 — Fall 2011 Prepared by: Doug Lloyd ’09 October 10, 2011 Below are several questions that are of the sort you will find on the quiz. While this is by no means a comprehensive review of all topics, it will help you study for the quiz. Of course, you should also attend section, and study the course materials . 1. Explain why some people might find the following image funny 1 : 2. Consider the following segment of code: #include <stdio.h> int main(int argc, char *argv[]) { char *myWord = "fish"; char *myOtherWord = "mouse"; int myInt = 12345678; double myDouble = 3.1415926535; printf("%d\n", sizeof(myWord)); printf("%d\n", sizeof(myWord[1])); printf("%d\n", sizeof(myOtherWord)); printf("%d\n", sizeof(myInt)); printf("%d\n", sizeof(myDouble)); printf("%d\n", sizeof(sizeof(myDouble))); } What will the output of this program be, if compiled on a 64-bit machine? 1 Courtesy of http://xkcd.com/138/ 1
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
3. Calculate in binary: 01011101 + 01101011 ---------- Convert your answer to decimal. 4. The ASCII value of p is 112. A character takes up 1 byte (8 bits) of space in memory. Give the binary representation of p in memory. 5. Describe the difference between a while loop and a do-while loop. Give an example of an instance where a while loop would be more useful and another where a do-while loop would be more useful and explain why. 6. Write a for loop that calculates the sum of the numbers 1 through 10 and stores the result in an integer variable sum . Then convert it to a while loop. 7. We would like to write the function mult binomials() , which takes two binomials of degree 1 (each represented as a one-dimensional array of 2 int s), and outputs a polynomial of degree 2, represented as a one-dimensional of 3 int s, which is their product. For example, we would represent: 4 x + 7 as int binomial[2] = { 4, 7 } ; 2 x + 0 as int binomial[2] = { 2, 0 } ; 5 as int binomial[2] = { 0, 5 } ; 3 x 2 + 7 x + 5 as int product[3] = { 3, 7, 5 } ; ...et cetera. Fill in the values for product[0] (the x 2 term), product[1] (the x term), and product[2] (the constant term): int *mult_binomials(int A[2], int B[2]) { int *product = (int *) malloc(3 * sizeof(int)); product[0] = ________________________; product[1] = ________________________; product[2] = ________________________; return product; } 8. Why is it okay that the return type of the function in Question 7 is int * instead of an int array? Is there a difference? Why or why not? 9. What is the major pointer error being made in Question 7? 10. What does the line #include <stdio.h> do in a program? Name one function that is declared in stdio.h . 2
Image of page 2
11. How would you declare some “container” of a type called student containing all of the following information: A string (without using CS50’s string type) for a student’s last name, An integer to represent that student’s ID number, A double-precision floating point number to represent their GPA, and A character (A, B, C, D) to represent their class year (freshman, sophomore, junior, senior).
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern