Single-line Comments in C

Single-line comments in C are used to add explanatory or descriptive text within a program's code. They are not compiled or executed and are solely meant for human understanding. They are denoted by the double forward slash (//) symbol and are used to provide additional information about the code or to temporarily disable certain lines of code. The steps to use single-line comments in C are as follows:

  1. Identify the line of code or section of code where you want to add a comment.
  2. Insert two forward slashes (//) at the beginning of the line where you want to add the comment.
  3. Write the comment text after the double forward slashes.
  4. Continue writing the comment text until the end of the line. Anything after the double forward slashes will be considered a comment and will not be executed or compiled.
  5. Repeat the process for each line where you want to add a comment.

Example:

int main() {
    int num1 = 10; // This variable stores the value 10
    int num2 = 20; // This variable stores the value 20

    int sum = num1 + num2; // Adding num1 and num2 to get the sum

    // Printing the sum to the console
    printf("The sum is: %d\n", sum);

    return 0;
}

In the above example, single-line comments are used to provide explanations for each step of the code. They help in understanding the purpose of the variables, the calculation of the sum, and the printing of the result to the console. These comments are ignored by the compiler and do not affect the execution of the program.