1.18.  Review Questions

[ fromfile: cppintro-questions.xml id: cppintro-questions ]

  1. What is a stream? What kinds of streams are there?

  2. Give one reason to use an ostrstream.

  3. What is the main difference between getline and the >> operator?

  4. What is the type of each expression in the following list?

    1. 3.14

    2. 'D'

    3. "d"

    4. 6

    5. 6.2f

    6. "something stringy"

    7. false

  5. In Example 1.31, identify the type and value of each numbered item:

    Example 1.31. src/types/types.cpp

    #include <QTextStream>
    
    int main() {
    	QTextStream cout(stdout);
    	int i = 5;
    	int j=6;
    	int* p = &i;                             1
    	int& r=i;      
    	int& rpr=(*p);
    	i = 10;
    	p = &j;                                  2
    	rpr = 7;                                 3
    
    	r = 8;                                   4
    	cout << "i=" << i << " j=" << j << endl; 5
    	return 0;
    }
    

    1

    *p: ______

    2

    *p: ________

    3

    *p: ________

    4

    rpr: ________

    5

    i: ________ j: ________


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

  7. What is the keyword "const" used for? Why and how would you use it in a program?

  8. What is the "address-of" operator? Why and how would you use it in a program?

  9. What is the "dereference" operator? Why and how would you use it in a program?

  10. What is a null pointer? Why would you define one in a program?

  11. What is a memory leak? What would cause one in a program?

  12. What might cause a segmentation fault (or, in Windows, a general protection fault)?

  13. What are the possible uses of const when dealing with pointers?

  14. What is a function's signature?

  15. What is meant by the term, "function overloading" ?

  16. Why is it an error to have two functions with the same signature but different return types in one scope?

  17. Why does main(int argc, char* argv[]) sometimes have parameters? What are they used for?