Day 26 Recap Questions
  1. What is a C++ reference?

  2. When should you use C++ references?

  3. What is the difference between a pointer and a reference?

  4. What is the output of the following?

     #include <iostream>
    	
     void modify(int& a, int& b) {
         a = a + b;
         b = a * 2;
     }
    	
     int main() {
         int x = 3, y = 5;
         int& ref = x;   
    	
         modify(ref, y); 
         ref = y;        
    	
         std::cout << x << " " << y << " " << ref << std::endl;
         return 0;
     }
    
  5. How do you dynamically allocate and deallocate memory in C++?
  6. What is wrong with the following code?

     #include <iostream>
    	
     using std::cout;
     using std::endl;
    	
     int main() {
       double *d_array = new double[5];
       for(int i = 0; i < 5; i++) {
         d_array[i] = i;
       }
    	
       delete d_array;
       return 0;
     }