Chapter 6

 < Day Day Up > 



Chapter 5

  1. What is the purpose of the main() function? Why does every C++ program need one?

    The main() function is the execution entry point for C++ programs. Every C++ program needs a main function so execution can be passed to it when the program is executed by the computer system.

  2. Describe how disassembling your programs and studying the results can improve your understanding of the C++ language and your computing platform.

    By disassembling C++ programs you get a feel for how program elements map to the processor's assembly language.

  3. What is the purpose of the preprocessor directive #include?

    The #include directive is replaced by the contents of the file it names during preprocessing.

  4. (True/False) You can use the C++ reserved keywords to name your own program objects.

    FALSE

  5. The sizeof operator will return the size of data types in what unit of measure?

    Allocation units

  6. You can either memorize C++ operator precedence or use ________________ to force precedence and make source code easier to read at the same time.

    parentheses

  7. Why can an unsigned data type represent a larger positive value than a signed data type?

    Because the most significant bit is not used to indicate a negative value.

  8. When negative numbers are shifted to the right using the >> operator what is the effect on the sign bit?

    It is carried along with the shift.

  9. How are string literals terminated?

    With \0 or null termination.

    Study the following code and answer the following questions:  1  #include <iostream>  2  using namespace std;  3  4  int val1 = 1;  5  6  int main(){  7    {  8      cout<<val1++<<endl;  9      int val1 = ::val1; 10      cout<<val1<<endl; 11   } 12   cout<<val1<<endl; 13  return 0; 14  }

    -What value will the new variable named val1 be initialized to on line 9?

    2

    -Which val1 will be printed to the screen on line 10?

    The val1 local to the block declared within the main() function.

    -What is the value of val1 printed to the screen on line 12?

    2

    -Describe the effect of using the unary scope resolution operator :: on line Why is its use necessary?

    The val1 declared on line 9 conflicts or hides the global val1 declared on line The :: operator is necessary to resolve the variable names.



 < Day Day Up > 



C++ for Artists. The Art, Philosophy, and Science of Object-Oriented Programming
C++ For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504028
EAN: 2147483647
Year: 2003
Pages: 340
Authors: Rick Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net