Programming in C: Unit I (b): Introduction to C

Using Comments

C Program

Many a time the meaning or the purpose of the program code is not clear to the reader. Therefore, it is a good programming practice to place some comments in the code to help the reader understand the code clearly.

USING COMMENTS

Many a time the meaning or the purpose of the program code is not clear to the reader. Therefore, it is a good programming practice to place some comments in the code to help the reader understand the code clearly. Comments are just a way of explaining what a program does. It is merely an internal program documentation. The compiler ignores the comments when forming the object file. This means that the comments are non-executable statements. C supports two types of comments.

• // is used to comment a single statement. This is known as a line comment. A line comment can be placed anywhere on the line and it does not require to be specifically ended as the end of the line automatically ends the line.

Programming Tip: Not putting the */ after the termination of the block comment is a compiler error.

 • /* is used to comment multiple statements. A /* is ended with */ and all statements that lie within these characters are commented. This type of comment is known as block comment.

Note that commented statements are not executed by the compiler. Rather, they are ignored by the compiler as they are simply added in the program to make the code uple who understandable by the programmer to other people who read it. It is a good habit to always put a comment at the top of a program that tells you what the program does. This will help in defining the usage of the program the moment you open it.

Ppppppppppppppppppppppppp

Commented statements can be used anywhere in the program. You can also use comments in between your code to explain a piece of code that is a bit complicated. The code given below shows the way in which we can make use of comments in Our first program.

/* Author: Reema Thareja

Description: To print 'Welcome to the world of C' on the screen */

#include <stdio.h>

int main()

{

printf("\n Welcome to the world of C ");

// prints message

return 0; // returns a value 0 to the operating system

}

Output

Welcome to the world of C

Since comments are not executed by the compiler, they do not affect the execution speed and the size of the compiled program. Therefore, using comments liberally in your programs aid other users in understanding the operations of the program as well as in debugging and testing.

Programming in C: Unit I (b): Introduction to C : Tag: : C Program - Using Comments


Programming in C: Unit I (b): Introduction to C



Under Subject


Programming in C

CS3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation



Related Subjects


Professional English II

HS3251 2nd Semester 2021 Regulation | 2nd Semester Common to all Dept 2021 Regulation


Statistics and Numerical Methods

MA3251 2nd Semester 2021 Regulation M2 Engineering Mathematics 2 | 2nd Semester Common to all Dept 2021 Regulation


Engineering Graphics

GE3251 eg 2nd semester | 2021 Regulation | 2nd Semester Common to all Dept 2021 Regulation


Physics for Electrical Engineering

PH3202 2nd Semester 2021 Regulation | 2nd Semester EEE Dept 2021 Regulation


Basic Civil and Mechanical Engineering

BE3255 2nd Semester 2021 Regulation | 2nd Semester EEE Dept 2021 Regulation


Electric Circuit Analysis

EE3251 2nd Semester 2021 Regulation | 2nd Semester EEE Dept 2021 Regulation


Physics for Electronics Engineering

PH3254 - Physics II - 2nd Semester - ECE Department - 2021 Regulation | 2nd Semester ECE Dept 2021 Regulation


Electrical and Instrumentation Engineering

BE3254 - 2nd Semester - ECE Dept - 2021 Regulation | 2nd Semester ECE Dept 2021 Regulation


Circuit Analysis

EC3251 - 2nd Semester - ECE Dept - 2021 Regulation | 2nd Semester ECE Dept 2021 Regulation


Materials Science

PH3251 2nd semester Mechanical Dept | 2021 Regulation | 2nd Semester Mechanical Dept 2021 Regulation


Basic Electrical and Electronics Engineering

BE3251 2nd semester Mechanical Dept | 2021 Regulation | 2nd Semester Mechanical Dept 2021 Regulation


Physics for Civil Engineering

PH3201 2021 Regulation | 2nd Semester Civil Dept 2021 Regulation


Basic Electrical, Electronics and Instrumentation Engineering

BE3252 2021 Regulation | 2nd Semester Civil Dept 2021 Regulation


Physics for Information Science

PH3256 2nd Semester CSE Dept | 2021 Regulation | 2nd Semester CSE Dept 2021 Regulation


Basic Electrical and Electronics Engineering

BE3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation


Programming in C

CS3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation