• Have Any Question?
  • contact@eitworld.com

C Program Structure





Every program in C programming follows as structure to make a program for more readable and more flexible so that anyone can understand the program function. C Program Structure contains Documentation, Pre-processor directive or header files, Main Function, Variables, Pre-defined functions and user defined functions, Statements and Expressions, Comments. In Structure of C Program, documentation for putting comments for the program, pre-processor directives includes header-files required by our C program, from main() function program execution starts, a C program can use system function or user defined function, in C everything is written in the form of statements and comments make our program more readable.Here eitworld.com provides the learning for C Programming Structure in easy and smart way.

Structure of C program contains various sections which are as follows:

  • Documentation
  • Preprocessor directive or header files
  • Main Function
  • Variables
  • Pre-defined functions and user defined functions
  • Statements and Expressions
  • Comments
    • Documentation: Documentation is an optional section. This is generally used to put comments for the program. Comments help to understand the programs in context of what we are developing in the program.
    • Header Files: This section includes header-files required by our C program. We can make our own header files and can use in the program.
    • main() functions: main() function must be present in the every C program. Execution of all C program begins with the main() function.
    • Symbolic Constants, variables and functions: These sections are declared after the header files if required. Global variables can be used in the whole program and we can use functions in whole program after defining the code for the functions.
    • Comments: The statement written in the /* & */ delimiters are known as comments which are not executed by the compiler. So we can say comments are not the part of the executable programs. We include comment in the program to understand the flow of program.

Simple Hello World Example

#include<stdio.h>

int main()

{

/*Simple Hello-World program in C*/

printf(“Hello-world”);

return 0;

}

  • #include: It is a preprocessor directive. This contains declaration and definition of various standard input-output functions used in C program.
  • main(): Every program written in C language must contain main() function. main() function is the starting point of every ‘C’program.
  • /*Simple Hello-World program in C*/: It is a comment. The statement written in the /* & */ delimiters are known as comments which are not executed by the compiler. So we can say comments are not the part of the executable programs. We include comment in the program to understand the flow of program.
  • printf(“Hello-world”):It is a predefine function defined in the stdio.h header file. It is used here in the program to print message “Hello-world”.
  • return 0:This command terminates C program (main function) and returns 0.

Some Programming Rules

  • Every C program must contain main function.
  • All statements should be written in lower case letters. Upper case letters are only used for symbolic constants.
  • Every C statement must end with semicolon.
  • The opening and closing braces should be balanced. For example if opening braces are 2; then closing braces should also be 2.

Compile and Execute C Program

Following steps are essential in executing a ‘C’ program:

Creation of a program

  • C program should be written in text editor like Turbo C2, BorLand C/C++ and Notepad.
  • Program written in C editor are saved with the extension “.C”.
  • The program saved with the .C extension is known as source program.

Compilation of C program

  • Compiler converts the source program saved with .C extension into Object code with “.obj” extension if there is not any error present in the source program.
  • If there is any error in source program then Compiler shows those errors to us.
  • To compile a program in Turbo C compiler you have to use Ctrl+F9 and in BorLand C/C++ 3.0 compiler you have to use the key Alt+F9.

Linking of C program

  • Linking is an essential process it put all the program files and functions together that are required by program.
  • In linking process program is linked with the header files and other libraries.

Executing the C program

  • After compilation the executable object code will be loaded in the computer’s main memory and the program is executed.
  • In Turbo C compiler execution of program is done with the key Ctrl+F9.

program-structure



Real Time Web Analytics