Writing Comments in C program

In C program, comments doesn’t have any use other than for better understanding of the developers of the source code in case you are writing big program and wants to remember what is the functionalities of the code blocks (functions/lines) in program.

Single Line Comment — Any text on a single line after // is considered as single line comment.

Multiline Comment — Any lines between “slash” “star” and “star” “slash” are considered as comments.

In C, you can’t have nested comments. Meaning you can’t write as, /* … some comment 1 … /* … some comment 2 …  */  */
This will not be a Valid nested comment.

 

#include <stdio.h>
// This is a single line comment.
// This program prints "Hello World" on Terminal

int main(void) {
        printf ("Hello World\n"); // This is Valid comment
        printf ("Hello World\n"); /* This is a Valid comment */
        printf /* This is a valid comment */ ("Hello World\n");
        /*
          This is multiple line
          Valid comment */
        return 0;
}
Android Android Commands Android Java Applications Application Libraries Bash / Shell Scripts Bluetooth driver Build Frameworks Commands and Packages Core Kernel C Programs Development Environment Setup Documents / Books Errors & Failures File Systems Framebuffer / Display Driver git Go Language Programs Hardware Platforms Home Kernel & Device Drivers Kernel Booting and Porting Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL NDK / Middleware / HAL Network Driver OS Concepts PHP Procfs Filesystem Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Userspace Utilities Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply