Main Page

Previous Page
Next Page

[Page 65 (continued)]


  • Single-line comments begin with //. Programmers insert comments to document programs and improve their readability.

  • Comments do not cause the computer to perform any action when the program is runthey are ignored by the C++ compiler and do not cause any machine-language object code to be generated.

  • A preprocessor directive begins with # and is a message to the C++ preprocessor. Preprocessor directives are processed by the preprocessor before the program is compiled and don't end with a semicolon as C++ statements do.

  • [Page 66]
  • The line #include <iostream> tells the C++ preprocessor to include the contents of the input/output stream header file in the program. This file contains information necessary to compile programs that use std::cin and std::cout and operators << and >>.

  • Programmers use white space (i.e., blank lines, space characters and tab characters) to make programs easier to read. White-space characters are ignored by the compiler.

  • C++ programs begin executing at the function main, even if main does not appear first in the program.

  • The keyword int to the left of main indicates that main "returns" an integer value.

  • A left brace, {, must begin the body of every function. A corresponding right brace, }, must end each function's body.

  • A string in double quotes is sometimes referred to as a character string, message or string literal. White-space characters in strings are not ignored by the compiler.

  • Every statement must end with a semicolon (also known as the statement terminator).

  • Output and input in C++ are accomplished with streams of characters.

  • The output stream object std::coutnormally connected to the screenis used to output data. Multiple data items can be output by concatenating stream insertion (<<) operators.

  • The input stream object std::cinnormally connected to the keyboardis used to input data. Multiple data items can be input by concatenating stream extraction (>>) operators.

  • The std::cout and std::cin stream objects facilitate interaction between the user and the computer. Because this interaction resembles a dialog, it is often called conversational computing or interactive computing.

  • The notation std::cout specifies that we are using a name, in this case cout, that belongs to "namespace" std.

  • When a backslash (i.e., an escape character) is encountered in a string of characters, the next character is combined with the backslash to form an escape sequence.

  • The escape sequence \n means newline. It causes the cursor (i.e., the current screen-position indicator) to move to the beginning of the next line on the screen.

  • A message that directs the user to take a specific action is known as a prompt.

  • C++ keyword return is one of several means to exit a function.

  • All variables in a C++ program must be declared before they can be used.

  • A variable name in C++ is any valid identifier that is not a keyword. An identifier is a series of characters consisting of letters, digits and underscores (_). Identifiers cannot start with a digit. C++ identifiers can be any length; however, some systems and/or C++ implementations may impose some restrictions on the length of identifiers.

  • C++ is case sensitive.

  • Most calculations are performed in assignment statements.

  • A variable is a location in the computer's memory where a value can be stored for use by a program.

  • Variables of type int hold integer values, i.e., whole numbers such as 7, 11, 0, 31914.

  • Every variable stored in the computer's memory has a name, a value, a type and a size.

  • Whenever a new value is placed in a memory location, the process is destructive; i.e., the new value replaces the previous value in that location. The previous value is lost.

  • When a value is read from memory, the process is nondestructive; i.e., a copy of the value is read, leaving the original value undisturbed in the memory location.

  • The std::endl stream manipulator outputs a newline, then "flushes the output buffer."

  • [Page 67]
  • C++ evaluates arithmetic expressions in a precise sequence determined by the rules of operator precedence and associativity.

  • Parentheses may be used to force the order of evaluation to occur in any sequence desired by the programmer.

  • Integer division (i.e., both the numerator and the denominator are integers) yields an integer quotient. Any fractional part in integer division is truncatedno rounding occurs.

  • The modulus operator, %, yields the remainder after integer division. The modulus operator can be used only with integer operands.

  • The if statement allows a program to make a decision when a certain condition is met. The format for an if statement is

    if ( condition )

    If the condition is true, the statement in the body of the if is executed. If the condition is not met, i.e., the condition is false, the body statement is skipped.

  • Conditions in if statements are commonly formed by using equality operators and relational operators. The result of using these operators is always the value true or false.

  • The declaration

    using std::cout;

    is a using declaration that eliminates the need to repeat the std:: prefix. Once we include this using declaration, we can write cout instead of std::cout in the remainder of a program.

Previous Page
Next Page