PracticeQuiz0-2011

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

Info iconThis 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
Background image of page 1

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

View Full DocumentRight 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
Background 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). 12. Given that we have one of these “containers” described in Question 13 called
Background image of page 3

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

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

This note was uploaded on 04/05/2012 for the course CS 50 taught by Professor Malan during the Fall '08 term at Harvard.

Page1 / 9

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

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online