C++ Demystified(c) A Self-Teaching Guide

  1. A computer program consists of step-by-step instructions to the computer from a computer programmer.

  2. A programming language is a language that resembles the structure and syntax of human language, and that is used by computer programmers to write instructions for computers.

  3. A function is a group of related instructions, also called statements, which together perform a particular task.

  4. A C++ program must have one main function, no more, no less.

  5. A standard library file is a file that defines commonly used objects, such as cout.

  6. The purpose of an include directive is to tell the program to include a particular standard library file in your application.

  7. A preprocessor is a program that scans the source code for include directives, and then inserts them into the source code of all files included by the include directives.

  8. The compiler is a program that translates the preprocessed source code (the source code after the insertions made by the preprocessor) into corresponding machine language instructions that are stored in an object file.

  9. The linker is a program that combines the object file with the necessary parts of the run-time library and creates an executable file.

  10. Persistent storage is not temporary like the other two: cache memory and RAM.

  11. One byte of information may be stored at a particular memory address.

  12. No. The size of a data type may vary depending on the compiler and operating system.

  13. The value of an unsigned data type is either zero or positive, never negative, while the value of a signed data type may be negative also.

  14. An ASCII value is a number between 0 and 255 that corresponds to a particular character.

  15. A literal string is a string, generally encased in double quotes, that is outputted literally, without evaluation.

  16. An expression is a code statement with a value that has to be evaluated when the program runs.

  17. Declaring a variable reserves memory for the storage of information and provides a name by which that information later can be referred to in code.

  18. No. An undeclared identifier compiler error will occur even though the variable is declared after it is referred to because the compiler reads the code from top to bottom, so when it reaches the first reference to the variable, it has not yet seen the variable declaration.

  19. The address operator is used to obtain the hexadecimal value of a variables memory address, whereas the sizeof operator is used to determine the number of bytes in memory required to store the variable on the compiler and operating system where the program is running.

  20. Initialization is when you assign a value to a variable in the same statement in which you declare that variable. By contrast, assignment is when you assign a value to a variable in a statement after the one in which you declare that variable.

  21. Overflow occurs when a variable is assigned a value too large for its range.

  22. You use the cin object for run-time assignment of values to variables .

  23. Division has more than one operator, / and %.

  24. The modulus operator cannot have a floating-point operand.

  25. The two division operators, / and %, cannot have zero as a second operand.

  26. total + = 5

  27. The result of 4 + 3 * 2 is 10, not 14, because multiplication has precedence over addition.

  28. The result of the expression 8 / 2 * 4 is 16, not 1, because of associativity. Multiplication and division have equal precedence, so the operations are performed from left to right.

  29. The result of the expression 15 / 4 is 3, not 3.75, because of integer division.

  30. C++, unlike some other programming languages, does not have an exponent operator. Instead, you use the pow function, defined in the cmath standard library, to raise a number to a certain power.

  31. An algorithm is a step-by-step logical procedure for solving a problem.

  32. There are two operands in a relational expression.

  33. The data type of the expression following the if keyword is Boolean.

  34. In an if / else if / else statement, you must have one, but only one, if part.

  35. In an if / else if / else statement, you may have more than one else if part.

  36. In an if / else if / else statement, you may omit the else part, in which case the statement becomes an if / else if statement.

  37. In a switch statement, the required data type of expression following the switch keyword is integer.

  38. In a switch statement, the expression following a case keyword must be a constant or a literal and therefore cannot be a variable.

  39. The default keyword in a switch statement corresponds to the else keyword in an if / else if / else statement.

  40. You can use nested if statements as an alternative to the logical And and Or operators.

  41. With the logical And operator, both Boolean expressions have to be true for the overall Boolean expression to be true.

  42. With the logical Or operator, both Boolean expressions have to be false for the overall Boolean expression to be false.

  43. The logical Not operator reverses the truth of a Boolean expression, making a true expression false and a false expression true.

  44. The increment operator increases a value by one.

  45. The decrement operator decreases a value by one.

  46. In the statement cout << --num, decrementing num occurs before the outputting of the value of num because the decrementing is a prefix.

  47. An iteration is each time a loop repeats.

  48. The usual purpose of the first expression in the parentheses following the for keyword is to initialize a variable which usually serves as the counter.

  49. The purpose of the second expression in the parentheses following the for keyword is to set the condition which must be true for the loop to continue to execute.

  50. The usual purpose of the third expression in the parentheses following the for keyword is to update a value, usually a counter.

  51. One or more of the expressions in the parentheses following the for keyword may be empty if handled elsewhere in the code.

  52. The purpose of the break keyword in a for loop is to prematurely terminate the loop.

  53. The purpose of the continue keyword in a for loop is to prematurely terminate the iteration of a loop.

  54. If you were going to use nested for loops to print rows and columns, you would use the inner for loop to print the columns .

  55. The do while loop executes at least once.

  56. The for loop is the best choice when the number of iterations is predictable.

  57. The parenthetical expression following the while keyword is for the condition.

  58. A flag is a Boolean variable whose value indicates whether a condition exists.

  59. A variables scope determines where it can be referred to in the code. A variables lifetime determines when it is destroyed .

  60. No. A function other than main does not have to be prototyped if it is defined above where it is called. However, it is a good idea to prototype each function other than main.

  61. No. A function need not have any arguments. If it has none, then the void keyword may be used in the parentheses following the function name.

  62. Yes. A function may have more than one argument. If so, the arguments are separated by commas.

  63. If a variable in main is passed by value to another function that changes the argument corresponding to that variable, the variable in main is not changed.

  64. If a variable in main is passed by reference to another function that changes the argument corresponding to that variable, the variable in main is changed.

  65. No. A function does not have to have a return value. If it doesnt have a return value, the keyword void is used in its place.

  66. No. A function may not have more than one return value.

  67. Yes. A function does not have to have a return value nor any arguments.

  68. Yes. A function may have both a return value and arguments.

  69. While the data type of an array may be integer, float, or character, a particular array cannot contain integers, floats, and characters . All the elements of an array must be of the same data type.

  70. The number of the starting index of an array is zero.

  71. The number of the ending index of an array is one less than the number of elements in the array.

  72. The two alternative methods of initializing an array are explicit initialization, in which the square brackets contain a numerical constant indicating the size of the array, or implicit initialization, in which the square brackets are empty and the size of the array is indicated by the number of elements on the right side of the assignment operator.

  73. The purpose of the null character is to signal cout when to end the output of a character array.

  74. The value of the name of an array is the base address of the array.

  75. When you pass an array name as a function argument, you are passing it by address.

  76. A pointer is a variable or constant whose value is the address of another variable or constant.

  77. The only difference between declaring an integer variable and an integer pointer variable is that the pointer variable declaration includes an asterisk, which either follows the data type or precedes the variable name.

  78. The data type in the declaration of a pointer refers to the data type of another variable (or constant) whose memory address is the value of the pointer.

  79. NULL is a constant defined in several standard libraries, including iostream . You assign a pointer NULL if it is too early in your code to know which address to assign to the pointer. The value of NULL, the memory address 0, signals that the pointer is not intended to point to an accessible memory location.

  80. You use the address operator to assign a pointer the address of another variable or constant.

  81. The purpose of the indirection operator is to obtain the value of the variable or constant to which the pointer points. This operation is said to dereference the pointer.

  82. Incrementing a pointer variable increases its value by the number of bytes of its data type.

  83. The purpose of the new operator is to dynamically allocate memory at run-time. The purpose of the delete operator is to deallocate dynamically created memory.

  84. You cannot use an assignment operator to assign the value of one C-string to another. You will be assigning an address instead of a value.

  85. Data is persistent when it survives after the program is finished.

  86. A file is a collection of data that is located on persistent storage, such as a hard drive, a CD-ROM, or other storage device.

  87. You should include the fstream standard library when your program reads from, or writes to, files.

  88. The fstream object may be used both for file input and file output.

  89. You can open a file with either the open member function or a constructor.

  90. The purpose of opening a file is to establish a path of communication between the file and a file stream object in your program.

  91. The purpose of closing a file is to free system resources that are required to maintain the path of communication between the file and the file stream object in your program.

  92. A constructor is a function that is automatically called when you attempt to create an instance of an object.

  93. File stream objects should be passed as function arguments by reference rather than by value.

  94. An is a relationship is involved in inheritance. An example is a student is a person.

  95. A has a relationship is involved in containership. Examples include that a car has an engine and a person has a birthday.

  96. A structure is a programmer-defined data type that enables you to package related variables that may be of different data types.

  97. You may initialize a structure using either an initialization list or a constructor.

  98. You can nest one structure within another structure, such as a birthday member variable of a Person structure being a Date structure itself.

  99. A structure may be passed by reference even if the function will not change the value of its member variables because less memory is required to pass the address of an object than the object itself, which may take up a lot of bytes. In this situation, you may precede the structure instance in the function argument list with the const keyword to prevent the function from inadvertently changing the values inside the structure instance.

  100. Member variables are, by default, public in a structure but private in a class.

Категории