Comments In C Programming Language

In this video tutorial lets learn about using comments in C programming language.

There are 2 types of comments in C program

1. Single Line Comment.
2. Multi-line comment.

Why Do We Need To Use Comments In Source Code?

1. Whenever someone looks at the code, they need not spend much time in understanding the logic and what that code snippet does. Instead they can simply read the comment and understand the purpose of the code snippet.

2. If there is comment at the top of program, anybody can read it and understand the purpose of the program itself. Usually developers display author information, title and the date of writing the program.

3. When there are multiple contributes to the source code, it’s best to have comments to credit the code contributor and also it’ll be helpful for the other contributes to look at the comment and understand the purpose of the code immediately, instead of tracking the logic and understanding it.

4. If we look at our own code after some time, comments will surely help us understand why we wrote the code in the first place!

Video Tutorial: Comments In C Programming Language


[youtube https://www.youtube.com/watch?v=fNu6hAVr6A0]

YouTube Link: https://www.youtube.com/watch?v=fNu6hAVr6A0 [Watch the Video In Full Screen.]

Source Code: Comments In C Programming Language

/*
 * Author: SATISH
 * Link: Technotip.com
 * Language: C Programming
 * Title: Comments In C
 * Multi-author: No
*/
#include<stdio.h>
#define PI 3.14  // Value of PI

int main()
{
    float r = 5.0;

    // Logic to calculate area of circle
    printf("Area of Circle is %f\n", (PI * r *r ));

    /*
       We could go further and
       add more features to this
       program in future.
    */    return 0;
}

Output:
Area of Circle is 78.500000

Single Line Comment
Whatever is written after double forward slash ( // ) in that same line, will be treated as comment.

Multi-Line Comment
Anything written inside a /* and */ is considered multiple comment. Text inside /* and */ can be written in multiple lines and all those things will be considered as comments.

Note: Comments are not executed as part of the program. Comments are not even compiled. They’re present only for the user to read and understand the purpose of the code.

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

PHP Comments, String Concatenation, Addition of Numbers & Hello World

Today lets see these 4 basic things:
1. The classic “Hello World” program.
2. Comment system in PHP.
3. Concatenation of Strings.
4. Addition of Numbers.



Classic “Hello World” program
Program to output simple string

1
2
3
<?php
          echo "Hello World";
?>

Comments:

1
// This is single line comment
1
# This is also a single line comment
1
2
3
/* This is how multi-line comments
    are written.
*/

Anything following a double forward slash or a hash( # ) symbol will be ignored by your parser. Comments are very important and are often ignored by programmers. Comments come handy when we come back to the codes and want to make some changes to the coding. So its always a good practice to write comments wherever appropriate.

Concatenation of Strings
Concatination is joining of two or more strings end to end. Ex: if we concatenate Micro and soft, it will become Microsoft.
In PHP, we use .[DOT] operator for concatenation. Below is an example:

1
2
3
4
<?php 
         echo "Micro" . "soft";
         echo "<br />Oracle, " . "Sun Microsystems";
?>

The output for the above php code is:

1
2
Microsoft
Oracle, Sun Microsystems

Addition of Numbers
We can use variables for addition of numbers or we can simply make use of echo or print for addition of numbers.

1
2
3
<?php
         echo 10+20;
?>

This gives 30 as the output.

1
2
3
<?php
         echo "5"+10;
?>

This gives 15 as output. The string “5” will be implicitly converted into number and will be added to the actual number 10.