Cambo Freelance
ទំព័រដើមសេវាកម្មអត្ថបទការបង្រៀនក្រុមវគ្គបណ្តុះបណ្តាលទំនាក់ទំនង
Cambo Freelance

Professional freelance team from Cambodia delivering technology-driven solutions with cultural insight and modern expertise.

ផ្ញើសាររបស់អ្នក

ត្រៀមចាប់ផ្តើមគម្រោងរបស់អ្នក? ទំនាក់ទំនងក្រុមរបស់យើង។

ទំនាក់ទំនង

សេវាកម្ម

  • Web & Mobile Development Services
  • Graphic Design & Branding Services

តំណភ្ជាប់មានប្រយោជន៍

  • ទំព័រដើម
  • សេវាកម្ម
  • ការសិក្សា
  • អំពីយើង
  • ទំនាក់ទំនង
  • តម្លៃ

© 2026 Cambo Freelance. រក្សាសិទ្ធិទាំងអស់។

TelegramFacebookLinkedInEmail
HomeTutorialsC++C++ Comments
⚡C++ Tutorials

50 lessons

Beginner(21)1C++ Introduction2C++ Getting Started3C++ Syntax4C++ Output5C++ Comments6C++ Variables7C++ Data Types8C++ Constants9C++ User Input10C++ Operators11C++ Strings12C++ Math13C++ Booleans14C++ Conditions15C++ Switch16C++ Loops17C++ Break and Continue18C++ Arrays19C++ Functions20C++ References21C++ Pointers
Intermediate(19)22C++ Classes23C++ Objects24C++ Constructors25C++ Access Specifiers
Advanced(10)41C++ Smart Pointers42C++ Templates43C++ Lambda Functions44
⚡

C++ Tutorials

Lesson 5 of 50

All lessons
Beginner (21)1C++ Introduction2C++ Getting Started
26
C++ Encapsulation
27C++ Inheritance
28C++ Polymorphism
29C++ Abstraction
30C++ Files
31C++ Exception Handling
32C++ Namespaces
33C++ Structures
34C++ Enumerations
35C++ STL Introduction
36C++ Vectors
37C++ Maps
38C++ Sets
39C++ Queues
40C++ Stacks
C++ Move Semantics
45C++ Multithreading
46C++ Design Patterns
47C++ Memory Management
48C++17 Features
49C++20 Features
50C++ Performance Optimization
3
C++ Syntax
4C++ Output
5C++ Comments
6C++ Variables
7C++ Data Types
8C++ Constants
9C++ User Input
10C++ Operators
11C++ Strings
12C++ Math
13C++ Booleans
14C++ Conditions
15C++ Switch
16C++ Loops
17C++ Break and Continue
18C++ Arrays
19C++ Functions
20C++ References
21C++ Pointers
Intermediate (19)22C++ Classes23C++ Objects24C++ Constructors25C++ Access Specifiers26C++ Encapsulation27C++ Inheritance28C++ Polymorphism29C++ Abstraction30C++ Files31C++ Exception Handling32C++ Namespaces33C++ Structures34C++ Enumerations35C++ STL Introduction36C++ Vectors37C++ Maps38C++ Sets39C++ Queues40C++ Stacks
Advanced (10)41C++ Smart Pointers42C++ Templates43C++ Lambda Functions44C++ Move Semantics45C++ Multithreading46C++ Design Patterns47C++ Memory Management48C++17 Features49C++20 Features50C++ Performance Optimization
⚡C++BeginnerLesson 5 of 50CamboFreelanceJune 19, 2026

C++ Comments

Learn how to write single-line and multi-line comments in C++ and understand best practices for documenting your code.


Tutorials › C++ › Comments
Beginner4 min readLesson 5 of 50

In This Lesson

  • Single-Line Comments
  • Multi-Line Comments
  • When to Use Comments
  • Quiz

Single-Line Comments

Single-line comments start with two forward slashes //. Everything after // on that line is ignored by the compiler.

// This is a single-line comment
cout << "Hello World!"; // This comment is at end of a statement

Multi-Line Comments

Multi-line comments start with /* and end with */. They can span multiple lines.

/* This is a multi-line comment.
   It can span many lines.
   The compiler ignores everything between the delimiters. */
cout << "Comments don't affect output!";

Full Example

#include <iostream>
using namespace std;

int main() {
    // Print a greeting message
    cout << "Hello!" << endl;

    /* This block demonstrates
       multi-line comments */
    cout << "Comments are for humans, not compilers." << endl;

    return 0; // End of program
}

Output:

Hello!
Comments are for humans, not compilers.

When to Use Comments

  • Explain complex logic that is not obvious from the code.
  • Temporarily disable code during debugging.
  • Document functions — what they do, parameters, return values.
  • Leave TODOs for future improvements.
Best Practice: Write comments that explain why something is done, not what is being done. Good code is self-explanatory; comments fill in the reasoning.

Exercise

Add a single-line comment above each cout line to explain what it prints.

#include <iostream>
using namespace std;

int main() {
    cout << "Name: Alex" << endl;
    cout << "Age: 25" << endl;
    return 0;
}
Show Solution
#include <iostream>
using namespace std;

int main() {
    // Print the user's name
    cout << "Name: Alex" << endl;
    // Print the user's age
    cout << "Age: 25" << endl;
    return 0;
}

Quiz

  1. Which syntax starts a single-line comment in C++?

    • A) #
    • B) --
    • C) //
    • D) **
    Answer

    C) //

  2. What happens to comments when the code is compiled?

    • A) They are printed to the screen
    • B) They cause compile errors
    • C) They are completely ignored
    • D) They are stored in the executable
    Answer

    C) Comments are ignored by the compiler and have no effect on the program.

Summary

  • Use // for single-line comments.
  • Use /* ... */ for multi-line comments.
  • Comments are ignored by the compiler.
  • Use comments to explain why, not what.
← Previous: Output Next: C++ Variables →
c++commentsbeginnerdocumentation
PreviousLesson 4: C++ OutputNextLesson 6: C++ Variables
Back to All Tutorials