C++ Crash Course: a fast-Paced Introduction



Yüklə 7 Mb.
Pdf görüntüsü
səhifə56/71
tarix20.09.2023
ölçüsü7 Mb.
#145939
1   ...   52   53   54   55   56   57   58   59   ...   71
C Crash Course A Fast-Paced Introduction by Josh Lospinoso

21
Comments
Comments are human-readable annotations that you can place into your 
source code. You can add comments to your code using the notation 
//
or 
/**/
. These symbols, 
//
or 
/**/
, tell the compiler to ignore everything from 
the first forward slash to the next newline, which means you can put com-
ments in-line with your code as well as on their own lines:
// This comment is on its own line
int the_answer = 42; // This is an in-line comment
You can use the 
/**/
notation to include multiline comments in 
your code:
/*
* This is a comment
* That lives on multiple lines
* Don't forget to close
*/
The comment starts with 
/*
and ends with 
*/
. (The asterisks on the 
lines between the starting and ending forward slash are optional but are 
commonly used.)
When to use comments is a matter of eternal debate. Some pro-
gramming luminaries suggest that code should be so expressive and self- 
explanatory as to render comments largely unnecessary. They might say 
that descriptive variable names, short functions, and good tests are usually 
all the documentation you need. Other programmers like to place com-
ments all over the place.
You can cultivate your own philosophy. The compiler will totally ignore 
whatever you do because it never interprets comments.
Debugging
One of the most important skills for a software engineer is efficient, effec-
tive debugging. Most development environments have debugging tools. On 
Windows, macOS, and Linux, the debugging tools are excellent. Learning 
to use them well is an investment that pays off very quickly. This section pro-
vides a quick tour of how to use a debugger to step through the program in 
Listing 1-8. You can skip to whichever environment is most relevant to you.
Visual Studio
Visual Studio has an excellent, built-in debugger. I suggest that you debug 
programs in its Debug configuration. This causes the tool chain to build a 
target that enhances the debugging experience. The only reason to debug 
in Release mode is to diagnose some rare conditions that occur in Release 
mode but not in Debug mode.


22
Chapter 1
1. Open main.cpp and locate the first line of 
main
.
2. Click the margin just to the left of the line number corresponding to 
the first line of 
main
to insert a breakpoint. A red circle appears where 
you clicked, as shown in Figure 1-4.
Figure 1-4: Inserting a breakpoint
3. Select 

Yüklə 7 Mb.

Dostları ilə paylaş:
1   ...   52   53   54   55   56   57   58   59   ...   71




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin