Homework #1

Due: in class, Thursday 1/12
65 points
    Coding and comprehension

  1. [10] Identify at least one of each of the following in the below code:
    #include 
    int main()
    {
        std::cout << "Enter two numbers:" << std::endl;
        int v1, v2;
        std::cin >> v1 >> v2;
        std::cout << "The sum of " << v1 << " and " << v2
                  << " is " << v1 + v2 << std::endl;
        return 0;
    }
    
  2. [5] What is the output of the above code after each of these inputs?
    - 4 7
    - 17 23
    - 5.6 3.2
    

  3. [10] Write a program to print "Hello, World" on the standard output.

  4. [9] Indicate which, if any, of the following output statements, are legal.
    std::cout << "/*";
    std::cout << "*/";
    std::cout << /* "*/" */;
    
    After you've predicted what will happen, test your answer by compiling a program with these three statements. Indicate the differences between your predicted output and what you learn from the compiler in your answer.

  5. Data types and variables

  6. [2] What is the difference between an int, a long, and a short value?
  7. [2] What is the difference between an unsigned and a signed type?
  8. [2] If a short on a given machine has 16 bits then what is the largest number that can be assigned to a short? To an unsigned short?
  9. [2] What value is assigned if we assign 100,000 to a 16-bit unsigned short? What value is assigned if we assign 100,000 to a plain 16-bit short?
  10. [8] Using escape sequences, write a program to print 2M followed by a newline. Modify the program to print 2, then a tab, then an M, followed by a newline.
  11. [6] Distinguish between an lvalue and an rvalue; show examples of each.
  12. [4] What, if any, are the differences between the following definitions:
    int month = 9, day = 7;
    
    int month = 09, day = 07;
    
  13. [5] What is the difference between the following two statements?
    int i = 10, r = i;
    
    int i = 10, &r = i;