Recent Posts

Friday, 29 December 2017

Structure of C Program


In the previous tutorial we learnt Rules for writing a 'C' Program.In this tutorial we will learn the Structure of C Program.The C program is the collection of instruction,and instruction is nothing but the statements in C.

Structure of C Program


#include<pre-processor directives>
[macro declaration and definition]
[global variable declaration]
main()
{
       local variable declaration with proper data type;
       :
       :
       statements;
       :
       :
}
[  user_defined_function_definition (arguments)]
       {
          statement_block;
        }
]

Explanation:

#include<pre-processor directives>:
     At this place we have to include all the header files,which are prototype for the statements, which are used in our program.

[Macro declaration and definition]:
     At this place we have to declare and define the definitions of the macro that are used in program.
It is optional.

[Global variable declaration]:
If we required global variables in our program then such variables are declared at this place.It is optional.

main():
This is the first statement of every 'C' program,without main() function 'C' program cannot be start.If we didn't include main() function in 'C' program then error will be occurred.So Every 'C' program must start with main() function.

Local variable declaration:
At this place we have to declare all the variables with proper data type,which are used in our program (in main() function).

Statements:
At this place, we have to write all the statements,which are used to solve the aim of program.

[User-defined-function-definition]:
If any user defined function is called in program,then its definition are given at this place.It is optional.

Example:

#include<stdio.h>
#include<conio.h>
main()
{
int a,b;
clrscr();
printf("Enter value of a and b ");
scanf("%d %d",&a,&b);
printf("Sum=%d",a+b);
getch();
}

Related Posts:

  • C Program to swap two numbers In the previous post we learnt about Program for addition of two numbers.In this post we learnt about  How to get two numbers and swap it #inc… Read More
  • How to write C Program In the C programming language Data type, operator, identifiers, keywords, constants, and variables are the basic building blocks of C Program.Before … Read More
  • addtion program in C In the previous tutorial we learn about simple program How to write Hello world in 'C'.and in this post we will learn how to sum two numbers in c p… Read More
  • Palindrome number in C Here we will see what is palindrome number and how to write a program for palindrome number. Palindrome number in C: A palindrome number that re… Read More
  • Structure of C Program In the previous tutorial we learnt Rules for writing a 'C' Program.In this tutorial we will learn the Structure of C Program.The C program i… Read More

0 comments:

Post a Comment

Followers

Popular Posts

Categories

social media

Text Widget

Powered by Blogger.

About Me

My name is junaid khan and i am a full time blogger and author of a blog tutorial called tutorialpointsolution.

String function

In the previous post we learn about what is String .we know that string is a collection of two or more characters.In string we can store al...

Search This Blog

Technology

Adbox

Recent Post

Breaking

Recent In Internet

Comments

Facebook

Pages

Comments

Pages

Recent

Pages

Technology