Friday, 12 January 2018

Write a First program in C/C++

Welcome back! In my first post, I tell you that C++ is a advanced version of C. It means that you must learn C language before starting C++.

First of all, We should know about a C program structure that is shown below:



A program is made up of different parts, which are as follow:

  • Documentation section:- Under this section, Programmer writes information related to his program such as- the purpose of writing programs, date of creation and programmer's name etc. To write an information such as  /*...............*/
  • Link section:- Under this section, the Header files(Input/output library) used in the program are added. Header files(I/O library) are of the following type.
       #include<stdio.h>
       #include<conio.h>
       #include<math.h>
       #include<graphics.h>......etc.

Note: A library is simply a package of code that someone else has wrriten to make coding easier. 

  • Defination section:- Constant value is defaced under this section such as:
       #define pi=3.14

  • Global variable declration section:- Global variable is a variable that can be used in any part of the program. All global variables in the program are declared under this section.
  • Main Function:- This is the main part of the program and the implementation of the program starts with this, it has two parts:
     i) Declration part:- The variables used in this part are declared.
    ii) Executable part:- Various actions in the program are displayed in this              section.

Example:

/* PROGRAM FOR ADD TWO NUMBERS*/                                                         
  #include<stdio.h>                                                                                       
  #include<conio.h>                                                                                      
      void main() 
 {                                                                                            
      int num1, num2, sum;                                                                             
      clrscr();                                                                                                  
      printf("Enter the two integer values to be added");                                     
      scanf("%d%d", &num1, num2, sum);                                                       
      sum=num1+num2;                                                                                       printf("Addition of %d and%d is %d\n", num1, num2, sum);                      
      getch();                                                                                                  
  }                                                                                                                

4 comments:

  1. Thanks..subscribe to our newsletter to get updates and continue reading.

    ReplyDelete
  2. Thanks..subscribe to our newsletter to get updates and continue reading.

    ReplyDelete
  3. the following information is so useful for me.. thanks a lot...

    ReplyDelete