Pages

Tuesday, 8 October 2013

Structure of a C Program :





Documentation Section:

Comment:

  • Comment is the description of the statement or program.
  • The compiler not compiles the comments.
C is supported to following types of comments
  1. Single Line Comment or Line Comment
  2. Multiple Line Comment or Block Comment

Single Line Comment or Line Comment:

  • It is represented with forward slashes ( // ).
  •  Single Line Comment can be placed in any line in the program .
  • The compiler not compiles at the starting of the comment to till end of the comment.

Ex: //write a program to display “c- language”.


Multiple Line Comment or Block Comment:

We will add one or more lines to single line comment then it is called Multiple Line Comment or Block Comment.
It is represented with
 /* -------------
    -------------
    ------------- */

Ex:
/* write a program to accept student details of sno,sname,m1,m2,m3 and calculate total,avg and display the result.*/

Header Files or Include Files:

Extension of h file or .h file is known as Header file.

The Header files having source code of pre-defined functions or included the source code of pre-defined functions.

Global Declaration:

The variables are declared out side of the main is called global declaration and the variables are called global variables. The variables are visible in all functions i.e. at the starting of the program to till end of the program.

Local Declaration:

The variables are declared in side of the main is called local declaration and the variables are called local variables those variable are visible in where we are declared.

void:

void can be placed before of any function then it can not return any value.  

main():

  • In c- language the execution of the program starts with main and ends with main.
  • What ever we write with in the main only.
  • With out main we can not write a c- program.


Declarative Statements:

The variables are declared in declaration part only these variables are used in process part or execution part. And these declarations are called declarative statements.

Process Statements:

Group of statement or Collection of  Statements or Collection of Instructions.
Note: function will be learn later chapters.

//Simple C - Program

#include<stdio.h>
void main()
{
printf(“c-language”);
}

printf():

It is a predefined function and it is used to display text or message or any data.

Syntax 1:

printf(string);

Ex:

printf(“c-language”);

Output:

C-language

Syntax 2:

printf(“format specifiers or control string”,var1,var2…. );

Ex:

printf(“%d%d”,10,20);

Output:

10 20

Note 1: printf() instructions or source code is available in stdio.h

stdio means standard input and out put. 

Note 2: in c language each and every statement ends with semi colon (;).



No comments:

Post a Comment