Comments in C Language [ For Beginners ]

There are several times, when we need to write Comments About the Code so other user can Identify What is the Code about.
Or some line of Codes or Characters, we Don’t want Compiler to run or skip in those Cases we use Comments.
But There Are Two Types of Comments in C Language.

C Language Single Line Comment

Single Line Comments just Control the Single line of Code or Character. We just have to write those line Who we want to Hide or don’t want to Execute.

Single line Comment Syntax

index.c

// This Is A Single Line Comment
Ad

Need a Personal Tutor?

I am here to help you with your Programming journey. HTML, CSS, JavaScript, ReactJS, NextJS, C, C++, C#, SQL and more.

Less then 10$/hSee Plans100% Free Trial + Money Back Guaranty

Multi-line Comment

Multi Line Comments can Control Multi line of Code or Character. We just have to write those lines Who we want to Hide or don’t want to Execute. Between These /* */ slash asterisk and asterisk slash sign.

index.c [Multi line Comment Syntax]

/* 
   line 1
   line 2
   line 3
*/

Using Comments as a Guide:

Most commonly, Comments are used to specify or placing lines as a Guide. So another user can easily Identify the Element/Code.
Using comment we can declare some kind of small Definition for our Element/Code. and Compiler will ignore those lines and Export/Run our program without any Problems.

Using Comments as a Guide Example

index.c

#include<stdio.h>
main(){

     int a=1; //this will create a Variable and assign 1 to the variable's value 
     printf("hellow"); //this will export hello on the Result screen

     /* 
     this will get commented out the Code
       printf("bye");
     so code won't Display on the Result screen
     */
}

Syntax C Program Language (Explained):

#include<stdio.h> :

#include<stdio.h> is a Header file that includes Slandered (str) Input Output (IO) Library/File. Because All Of the C’s In build Functions are declared in <stdio.h> File.

Main Function main() :

main() main function is the entry point of C program. When We Run our C program the execution Control Directly to the Main Function [main()] and gave us result in output.

Print Function printf():

printf() is also a Function of C. Print Function is used to print “character, string, float, integer” ETC to the output screen.
So whatever we write between printf() inverted commas (” “) that will be printed on the output Screen.

Single Line Comment [//]

C Language Single Line Comments just Control the Single line of Code or Character.We just have to write those line Who we want to Hide or don’t want to Execute on run After These [//] Double slash sign.

/* */ Multi-line Comment

Multi Line Comments can Control Multi line of Code or Character. We just have to write those lines Who we want to Hide or don’t want to Execute on run Between These /* */slash asterisk and asterisk slash sign.

getch()

getch() usually used to get Character values but here we are using getch to add a pause to the output so we can see our values in the Output Screen.

Ad

Need a Personal Tutor?

I am here to help you with your Programming journey. HTML, CSS, JavaScript, ReactJS, NextJS, C, C++, C#, SQL and more.

Just 10$/hSee Plans100% Free Trial + Money Back Guaranty
Logo