Name: ____________________________________________________ Alpha: _____________ Section: ________

Describe help received: _________________________________________________________________

See the bottom for how to submit your work.

Due: Before 0800 on next class day

  1. (10 pts) Read today's lecture notes. Honestly declare how you read the notes.
    1. (10 pts) I read the notes carefully. I have a good understanding of the topics therein.
    2. (10 pts) I read the notes carefully, but I don't really understand the following points well:
      
      
      
      
    3. (0 pts) I didn't read the notes carefully.
  2. [10pts] Provide the type of each expresssion. Write ERROR if the expression is illegal.
    
    int x = 1;
    int* px = &x;
    char c = 'a';
    char* pc = &c;
    string s = "hello";
    
    expression type expression type
    &x *x
    px &px
    *px *s
    pc *pc
    *c &c
  3. [10pts] Consider the following program:
    
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
      int a = 10, b = 7;
    
      // the first cout-statement
      cout << "&a=" << &a << ", &b=" << &b << endl;  
    
      int* p;
      uint64_t addr;          
      cin >> hex >> addr;     
      p = (int*) addr;        
    
      int n;
      cin >> n;
      *p = n;
    
      // the second cout-statement
      cout << "a=" << a << ", b=" << b << endl; 
      return 0;
    }
    
    Suppose the program output was as follows:
    &a=0x7ffff83497e0, &b=0x7ffff83497e4
    a=10, b=20
    
    1. What was the input from the user?
    2. Give a simple diagram (i.e., with three boxes each for a, b, p) in this situation, when the program control is at the end of main.

Bring to class