Skip to content

Latest commit

 

History

History
59 lines (49 loc) · 1.92 KB

File metadata and controls

59 lines (49 loc) · 1.92 KB
title Comments (C++) | Microsoft Docs
ms.custom
ms.date 11/04/2016
ms.reviewer
ms.suite
ms.technology
devlang-cpp
ms.tgt_pltfrm
ms.topic language-reference
dev_langs
C++
helpviewer_keywords
code comments, C++
comments, documenting code
comments, C++ code
white space, C++ comments
ms.assetid 6fcb906c-c264-4083-84bc-373800b2e514
caps.latest.revision 6
author mikeblome
ms.author mblome
manager ghogen
translation.priority.ht
cs-cz
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
pl-pl
pt-br
ru-ru
tr-tr
zh-cn
zh-tw
translationtype Human Translation
ms.sourcegitcommit 3168772cbb7e8127523bc2fc2da5cc9b4f59beb8
ms.openlocfilehash 958f0b4bab463f0456c0b40094f1d09119ed970f

Comments (C++)

A comment is text that the compiler ignores but that is useful for programmers. Comments are normally used to annotate code for future reference. The compiler treats them as white space. You can use comments in testing to make certain lines of code inactive; however, #if/#endif preprocessor directives work better for this because you can surround code that contains comments but you cannot nest comments.

A C++ comment is written in one of the following ways:

  • The /* (slash, asterisk) characters, followed by any sequence of characters (including new lines), followed by the */ characters. This syntax is the same as ANSI C.

  • The // (two slashes) characters, followed by any sequence of characters. A new line not immediately preceded by a backslash terminates this form of comment. Therefore, it is commonly called a "single-line comment."

The comment characters (/*, */, and //) have no special meaning within a character constant, string literal, or comment. Comments using the first syntax, therefore, cannot be nested.

See Also

Lexical Conventions