C++ Tutorials

11. Comments in C++

By: Stanley B. : 2011-02-19

Description: There are two kinds of comments in C++: single-line and paired. A single-line comment starts with a double slash (//). Everything to the right of the slashes on the current line is a comment and ignored by the compiler.


12. while loop in C++

By: Stanley B. : 2011-02-19

Description: A while statement provides for iterative execution. We could use a while to write a program to sum the numbers from 1 through 10 inclusive as follows:


13. for loop in C++

By: Stanley B. : 2011-02-19

Description: In our while loop, we used the variable val to control how many times we iterated through the loop. On each pass through the while, the value of val was tested and then in the body the value of val was incremented.


14. Programming errors a compiler will detect in C++

By: Stanley B. : 2011-02-19

Description: Part of the compiler's job is to look for errors in the program text. A compiler cannot detect whether the meaning of a program is correct, but it can detect errors in the form of the program. The following are the most common kinds of errors a compiler will detect.


15. if in C++

By: Stanley B. : 2011-02-19

Description: A logical extension of summing the values between 1 and 10 is to sum the values between two numbers our user supplies. We might use the numbers directly in our for loop, using the first input as the lower bound for the range and the second as the upper bound. However, if the user gives us the higher number first, that strategy would fail: Our program would exit the for loop immediately. Instead, we should adjust the range so that the larger number is the upper bound and the smaller is the lower. To do so, we need a way to see which number is larger.


16. Using the Built-in Arithmetic Types in C++

By: Stanley B. : 2011-02-19

Description: The number of integral types in C++ can be bewildering. C++, like C, is designed to let programs get close to the hardware when necessary, and the integral types are defined to cater to the peculiarities of various kinds of hardware. Most programmers can (and should) ignore these complexities by restricting the types they actually use.


17. Escape Sequences for Nonprintable Characters in C++

By: Stanley B. : 2011-02-19

Description: Some characters are nonprintable. A nonprintable character is a character for which there is no visible image, such as backspace or a control character. Other characters have special meaning in the language, such as the single and double quotation marks, and the backslash. Nonprintable characters and special characters are written using an escape sequence. An escape sequence begins with a backslash. The language defines the following escape sequences:


18. Character String Literals in C++

By: Stanley B. : 2011-02-19

Description: All of the literals we've seen so far have primitive built-in types. There is one additional literalstring literalthat is more complicated. String literals are arrays of constant characters.


19. Multi-Line Literals in C++

By: Stanley B. : 2011-02-19

Description: There is a more primitive (and less useful) way to handle long strings that depends on an infrequently used program formatting feature: Putting a backslash as the last character on a line causes that line and the next to be treated as a single line.


20. Lvalues and Rvalues in C++

By: Stanley B. : 2011-02-19

Description: Some operators, such as assignment, require that one of their operands be an lvalue. As a result, lvalues can be used in more contexts than can rvalues. The context in which an lvalue appears determines how it is used. For example, in the expression