What are the comments in the C language?

What are the comments in C Language? Remark is a non-executable line in supply code used to explain a chunk of code or program. Feedback supplies inline documentation of source code and enhances the readability of the code. It describes what a chunk of code does.

Feedback is for readers not for compilers. They make supply code extra developer pleasant.

The compiler has nothing to do with feedback, it’s a non-executable piece of code. Due to this fact, throughout the compilation process, the pre-processor removes all feedback from the supply code.

C programming helps two kinds of commenting model.

  1. Single line feedback
  2. Multi-line feedback

Click Here to learn more at Teche Programmer

Single line feedback

Single line feedback starts with // double ahead slash character. Characters following // is handled as a remark and isn’t executed by the compiler. Single line feedback is greatest suited while you wish to add quick elements a few complicated code that may be described in a line.

Instance program to exhibit single line feedback

#embody <stdio.h> // Embody header file

// Place to begin of program
int important()

Multi line feedback

Single line remark present assist so as to add a quick description concerning the code in a single line. Nevertheless, most frequently it’s required so as to add a lengthy description about working of the code spanning throughout a number of traces. Positively in such a scenario you possibly can add a number of single line feedback. However, it is suggested to make use of multi-line feedback.

Multi-line feedback is used so as to add an in-depth description concerning the code. It begins with /* character and ends with */. Characters between /* */ are handled as feedback.

Multi-line feedback can span up to a number of traces. As well as, you should use multi-line feedback for each single in addition to a number of line commenting.

Instance program to exhibit multi-line feedback

 * @creator	Teche Programmer
 * @description	C program so as to add two numbers.
 *              Program reads two numbers from person and 
 *              shows the sum of two numbers.

#embody <stdio.h>

int important()

    /* Variable declarations */
    int num1, num2, sum;

    /* Reads two quantity from person */
    printf("Enter two quantity: "); 
    scanf("%dpercentd", &num1, &num2); 

    /* Calculate the sum */
    sum = num1 + num2;

    /* Lastly show sum to person */
    printf("Sum = %d", sum);

    return 0;

Click Here to learn about basic program in C — Teche Programmer

Benefits of commenting a program

Each developer will need to have a behavior of commenting supply code. It’s as necessary as cleaning your lavatory. I already talked about a nicely commented program is straightforward to learn and keep.

Allow us to contemplate the next piece of code.

void strcpy(char *src, char * dest)

At this level with little information on programming. Do you’ve got any concept of what the above piece of code will do? Now contemplate the identical code once more.

 * Perform to repeat one string to a different.
 * @src  Pointer to supply string
 * @dest Pointer to vacation spot string
void strcpy(char * src, char * dest)

     * Copy one after the other characters from src to dest string.
     * The loop terminates after assigning NULL
     * character to src string.
    whereas(*(src++) = *(dest++));

The above-commented program provides you a fundamental concept concerning the code. Which is the place feedback is helpful. The second program is extra cleaner and readable for builders.

Learn more at Teche Programmer — Click Here

Leave a Reply

Your email address will not be published. Required fields are marked *