Program Structure Of C

3 – Program Structure Of C Language

Before we learn the basic building Blocks of C programming, let us look at a minimum C program structure so that we can take it as a reference in the coming chapters.

Parts Of C language

C program basically consists of the following parts:

  • Preprocessor Directories/Commands
  • Functions
  • Variables
  • Statements & Expressions
  • Comments

Examples of above in this Simple Code

Let us look this simple code:

Let us take a look at the different parts of the above program:

  • In the first line of the program #include is a Preprocessor command, which tells C compiler to include stdio.h file before actual compilation.
  • In the next line, int main() is the main function From where the program execution begins.
  • The Third line is a comment & it is not compiled by the Compiler & it is added as additional comments in the program.
  • In the fourth line, Printf(…) is an Output function available in C which is used to display message Hello, World on the screen.
  • The next Line return 0; terminates the main function & returns the value 0.

Compile & Execute C Program

Now I will tell you that how to Save Source Code in a file, Compile & run it.

Following are the simple steps:

  • Open a text editor & add the above Code.
  • Save the File as Hello.c
  • Open a Command Prompt & go to the directory where the files are saved.
  • Type GCC Hello.c & Press Enter to compile the code
  • If there is no error in the code than CMD will generate a.out executable file .
  • Now type a.out to execute the program
  • You will see Hello World as output printed on the Screen.

Subscribe our channels:

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.