Structure of C Program

c program structure


C PROGRAM  STRUCTURE:
Different programming languages have their own format of coding. The basic components of C program are
  • main()
  • pair of curly braces {,}
  • declarations and statements
  • user define functions   

   
                                                          C PROGRAM STRUCTURE 


              
                   PREPROCESSOR STATEMENTS
                               GLOBAL DECLARATION;        
       main()
      {                                                                      
                       DECLARATIONS;
                       STATEMENTS;
       }
         USERDEFINE FUNCTIONS



PREPROCESSOR STATEMENTS:
These statements are begin with symbol# and are also called preprocessor directives. These statements tells the compiler that before actual compilation include header files and symbolic constants in C program.


                                                PREPROCESSOR STATEMENTS


    #  include<stdio.h>             : for the standard input/output functions
    # include "test.h"                 : for file inclusion of header file test
    # define NULL 0                : for defining symbolic constants ,NULL=0   
    # include<conio.h>              : for the console input/output



GLOBAL DECLARATION:
Functions or variables who existence is known in the main() function and other user define functions called global variables or global functions and their declaration are called global declaration. Global declaration should be made before main().

main():
As the name itself indicate that this is the main function of every C program. It should be written in lowercase letters and not terminated with semicolon ;. Execution of every C program starts from the main(). No C program executed without main().
NOTE:There must be single main() function in every C program. It calls user define functions and other library functions.

BRACES:
In every C program pair of curly braces are used. The right brace shows the end of the main() function while left brace shows or indicate the starting of main() function. These braces also indicates the beggning and end of user define functions.

DECLARATION:
Arrays, function , variables are used in C program are declared and initilized with their basic data types.

STATEMENTS:
Since we all know computer is a machine and doesnot think itself. We have to provide some instruction to the computer to perform task or specific operations. Instructions may be arithmetic statements,control statements, input output statements and other statements. They include comments which are explanatory notes of instructions. The format of these instructions are /* and */ . Comments are not executed and compiled.

USERDEFINE FUNCTIONS:
As the name incates userdefine means these functions are defined by user and contains a set of statements to perform specific task. Userdefine function are written before or after the main() function.

EXAMPLE OF SIMPLE C PROGRAM:
#include<stdio.h>
main()
{
printf(" WELCOME TO C  /n");
}
OUTPUT OF PROGRAM

WELCOME TO C
Explanation:

First line tells the compiler to include header file that is standard input/output file to perform reading and printing the data. Second line is main() that is main function of C Program. Body of C program contain only one statement that is
printf(" welcome to c/n")
When the statement is executed main() calls printf() and printf() is included in header file that is<stdio.h>. The printf() prints Welcome to C on the screen of computer.


0 Response to "Structure of C Program"

Post a Comment

Popular Posts

Label

1 Sidebar 2 Columns 3 Columns Footer 3rdball 4 Columns Footer Alex Alvaro Antsasia Arlinadesign Averie Barry BASIC CONCEPTS Basil Bayna Fast BeautyPress BeautyTemplates Beckel Best Best - Clean Beyonce Pro BioMag BlackMag Blanter Nova Blogger Card Bloggertheme9 Blogish Bpress Brakt C LANGUAGE C PROGRAMS C++ LANGUAGE C++ PROGRAMS Carella Cellar Charlotte Chooko Lite Clara Clean Combo One Cooperate Crusade Darry Dorman Dreamway Dunia Blanter eCars EduAcademy EducationPress Elise Elvan Eva Everyday FabNews Fashion Fashion Blogger Template Fashion Gossip FastCars Fedo FlashNews Fredy Portfolio Gaming Globus GoodTime Goomsite HTML LANGUAGE iGaming Indicate Innove Insomnia InspiredNews iSoft Jasmine Kalem Landscaping Lashira Lavelle Lily Fashion Limax Linea Lionex Luminescence Lite Lumix Luxury Magazine MagazinePro MAJOR DIFFERENCES MarketingBlog Martin MaxiMag Medica Mega Melissa Mercury MeshMag Minimag Minimalist MiniNews MovieKhor msdesignbd MusicLand Neko NetZine New Spread News16 Newsflash NewsForce NewsIdea Newspaper News NewsPro Nubie Fast Odd Themes Optima PaperMag PaperMag blog Parhlo Perfection Personal Personal Blog Photosout PixelZ Power Blog Premium Themes ProfileMag Purez Rano ReadNews Real estate Remito Grid Responsive Revo Robusta Rotario Saara SeoBoost Settle Shouters Simple Catch SimpleClean Sketchly SNews SolidMag Someo Sophie Sora Sora Bank Sora Home Sora News Responsive Sora One Sora Ribbon Spido Sticko Stucco Sure Mag Swift Tech Tech Pro Techia Techmax TechSpot TemplateClue Templateism Templatesilk Templatesyard Templatezy The Freelancer TheBlogger TheFocus Themeforest Themexpose TIPS AND TRICKS Topside TravelMag Trendy Trendy Travel Tumblr Under Construction Uong Jowo Veethemes Vertox VideoPlay Vigo Waverly way2themes WebBiz Wedding X-Mag Zealer ZetaMag