Ads

Basic Terms in C programming language


DELIMITERS:


  • Delimiters are the characters which separate the code or indicate the code in separate blocks, in C we have braces as delimiters.
     {         Start of function or block
      }         End of the function or block
  • We can write one block of statements in another block of statements as shown in the below program i.e. we can nest block of statements.

Example Program: Delimiters_Example

#include<stdio.h>
int main()
{
    int a;
    a=3+4;
   printf("\n Value of a is %d",a);
 {     /* This is start of block */
    int b=6;
    printf("\nValue of b is %d\n",b);
 }     /* This is end of a block */
}


STATEMENT:


  • A C program is made of functions and in functions we have statements, statements are the instructions given by a programmer to command a compiler how the function should work.
  • In C programming language statements are executed one after the other unless we use them in loops and control statements.
  • We can write a block of statements in between braces, we will use the block of statements more commonly in chapter called control statements.  

STATEMENT TERMINATOR:

  • In C each and every statement should end up with a semicolon (  ;  ).
  • By using semi colon at the end of each and every statement we indicate compiler that the statement has ended. And that semicolon is known as Statement Terminator.
  • For example
    i=0
    sum= a + b are called Statements.
  • But each and every statement should end with a symbol semi colon `;’ , so while programming in C, the above statements should be written as shown below.
    i=0;
    sum=a+b;

    In short a Statement Terminator is a semicolon which indicates the compiler that the statement is ended.
  • NOTE: In C programming language a statement without a Statement Terminator yields error.

COMMENTS:

  • Comments are those parts of the code which are not executed.
  • So a clever programmer use comments to indicate or give some information about the code, to make him understand the code if he revisits the same code for minor modifications or upgrade after few months or years.
  • Comments can be used anywhere in a C program.
  • There are two types of comments
    i) LINE COMMENT
    ii) BLOCK COMMENT

i)LINE COMMENT:

  • The comments contained only in one line are called Line Comments.
  • Two forward slashes are used in front of the line to comment out a line `//’.
  • Probably they are not available in old compilers.
Examples:
  • //This is a line comment.
  • int i=5; //The whole line after slashes are commented out.
NOTE: Some programmers avoid using line comment instead they go for block comment.
Why?
Because, line comment was not present in older compilers. It was incorporated into C from C99 standard.

ii) BLOCK COMMENT:

  • Block comments are the comments contained in multiple lines and they begin with forward slash, asterisk /* and ended with asterisk, slash */
  • If you begin a Block Comment then you definitely have to end it, else complier think that the whole program after `/*’ as a comment and thus it is not compiled.
  • Comments cannot be nested. They might lead to errors.
Examples:
  • /*this is a block comment*/
  • Int i=5; /* This is first line.
    And this is second line. These two lines are commented out, as they are enclosed in between block comment*/

EXAMPLE PROGRAM:


/**********************************************
PROG NAME            : Addition
PROGRAMMER’S NAME    : Ramana
OPERATION            : This program prints the sum of two numbers.
DATE                : 13 July 2014
***********************************************/
#include<stdio.h>
//Below is the main function
int main()
{  
   int sum, a=5, b=6;
   sum= a + b;           /*I am adding a and b*/
   printf("\nSum is %d", sum);
//above is a printf function which print’s the sum value;
   return 0;
}   //close of main



NOTE: Comments can also be used to indicate your co-worker about the functioning of your code. And yes, it is more helpful to write comments when you are working in groups or working for large organization. In industry many programmers work together and divide their work into parts and if you are assigned to create a part of code and pass it to your fellow co-worker, you can indicate your work using comments.

No comments:

Post a Comment