Skip to main content

Who Else Wants To Know The Mystery Behind C++ comments?

 C++ Comments



C++ Comments

Comments can be used to explain C++ code, and to make it more readable. It can also be used to prevent execution when testing alternative code. Comments can be singled-lined or multi-lined.


Single-line Comments

Single-line comments start with two forward slashes (//).


Any text between // and the end of the line is ignored by the compiler (will not be executed).


This example uses a single-line comment before a line of code:


Example

// This is a comment

cout << "Hello World!";






This example uses a single-line comment at the end of a line of code:


Example

cout << "Hello World!"; // This is a comment

C++ Multi-line Comments

Multi-line comments start with /* and ends with */.


Any text between /* and */ will be ignored by the compiler:


Example

/* The code below will print the words Hello World!

to the screen, and it is amazing */

cout << "Hello World!";





Single or multi-line comments?






It is up to you which you want to use. Normally, we use // for short comments, and /* */ for longer.


Comments

Popular posts from this blog

Who Else Wants To Know The Mystery Behind C++ Output ?

 C++ Output (Print Text) The cout object, together with the << operator, is used to output values/print text: for example ; #include <iostream> using namespace std; int main() {   cout << "Hello World!";   return 0; } Note: You can add as many cout objects as you want. However, note that it does not insert a new line at the end of the output: #include <iostream> using namespace std; int main() {   cout << "Hello World!";   cout << "I am learning C++";   return 0; }

Who Else Wants To Know The Mystery Behind C++ syntex?

C++ Syntax C++ Basic Syntax Object − Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behaviors -... Class − A class can be defined as a template/blueprint that describes the behaviors/states that object of its type. for example ; #include <iostream> int main() {   std::cout << "Hello World!";   return 0; } Example explained Line 1: #include <iostream> is a header file library that lets us work with input and output objects, such as cout (used in line 5). Header files add functionality to C++ programs. Line 2: using namespace std means that we can use names for objects and variables from the standard library. Don't worry if you don't understand how #include <iostream> and using namespace std works. Just think of it as something that (almost) always appears in your program. Line 3: A blank line. C++ ignores white space. But we use it to make the code more readable. Line 4: Another thing that always app...

Who Else Wants To Know The Mystery Behind C++ COMPILER?

 Intel oneAPI DPC++/C++ Compiler and Intel C++ Compiler Classic are Intel’s C, C++, SYCL, and Data Parallel C++ (DPC++) compilers for Intel processor-based systems, available for Windows, Linux, and macOS operating systems.[3] Overview Intel oneAPI DPC++/C++ Compiler is available for Windows and Linux and supports compiling C, C++, SYCL, and Data Parallel C++ (DPC++) source, targeting Intel IA-32, Intel 64 (aka x86-64), Core, Xeon, and Xeon Scalable processors, as well as GPUs including Intel Processor Graphics Gen9 and above, Intel Xe architecture, and Intel Programmable Acceleration Card with Intel Arria 10 GX FPGA.[4] Like Intel C++ Compiler Classic, it also supports the Microsoft Visual Studio and Eclipse IDE development environments, and supports threading via Intel oneAPI Threading Building Blocks, OpenMP, and native threads. DPC++[5][6] builds on the SYCL specification from The Khronos Group. It is designed to allow developers to reuse code across hardware targets (CPUs and ...