All lessonsOpen Open Open Open Open
1. Getting started
Comments and program structure
0 of 5 activities0%
Reading 1
Comments do not run
Use comments to explain intent. They are ignored by the compiler.
A line comment starts with // and runs to the end of that line. A block comment starts with /* and ends with */.
C++ statements usually end with a semicolon. Curly braces { } group statements into a block, such as the body of main.
// This is a line comment
int x = 3; // also a line comment
/*
This is a block comment.
It can span several lines.
*/
Check 2
Which line is a comment?
Which of these is a valid C++ comment?
Fill in 3
End of a statement
Try it 4
A program with comments
Run this program. Then uncomment the second cout line and run again.
main.cpp
Loading editor…
Output will appear here.
Assignment 5
Print 42
Write a program that prints 42 and a newline. You may include a comment.
main.cpp
Loading editor…