Earn while u Learn

Tips tweaks hacks on computer with C C++ VB tutorials and ways to earn money online

ad

Structure of C program and Running a Program in C

Structure of a C program
C is a structured language, made up of collection of procedures which consists of declarations, statements and other elements, C compiler starts the execution from the function name   main(). Every C program have the function main() which is special function and it may also contain other functions or user defined functions.
The statement or a group of statements under the functions should be present within a pair curly braces { }. Each statement should be terminated by a semicolon ;  .
The program structure in C
  • Including the header files
  • Global variables and functions declaration which is optional.
  • Main function
  • Local variable and Function declaration
  • Statements
  • other functions
Remark Statement of C
Comments / Remarks in C begin with  /* ( a slash and star) and end with   */ ( a star and slash). You can enter multi-line remarks or comments in C with a beginning   /* ..... comments.....  */

Example of a C program :
_____________________________
/* A program calculate the sum two numbers */
#include[stdio.h] /* including header file stdio.h
#include[conio.h]
main()
{
int a,b,sum;
printf("enter two numbers")
scanf("%d%d",&a,&b);
sum=a+b;
printf("the sum of two numbers = %d ", sum);
}
________________________________

Running a program
A C program must be converted to .exe or .com to run directly and also for hiding the code. But while writing the code you can run the program by ctrl+F9.    Now to make a C code or program .exe then simply press F9, it will save the program in xxx.exe  (where xxx.your file name)

0 comments:

Sign in / Join

Labels