Structure Of A C Program

I've already given a quick intro on C Programming and without any further delay Let's understand the structure of a C Program or the Basic Components which makes up a C Program. Click to check the last Post →

                        Structure Of A C Program

 A C Program is composed of various components which includes-
  • Preprocessor  Commands( include,define. )
  • A Global Variable Section ( a variable with Global Scope)
  • One/ More Functions(Piece of Code Performing the required job)

 

                                            Hello World (First C Program

 ----Use an IDE such as Turbo C++ and write the following codes.
                                       #include      //  or can use #include"stdio.h"
                                                   int main()
                                                  {
                                                     printf("\n HELLO WORLD");
                                                     return 0;
                                                  }
Output:
HELLO WORLD 

   
The above code is the simplest snippet to compile a code that prints HELLO WORLD.
I'll be defining every object used and will be used in coming programs...

                                              1. Preprocessor Commands 

It can be divided into two parts.

                       a. #include -- Known as preprocessor Directive

   
 Preprocessor Directive let's the compiler to understand that the specific line is to be connected to some header file and the source file will contain all instructions prior to it.
Computer is a dumb machine and without instructions we can't ask it to perform any task, similarly in C in order for the compiler to understand the keywords or other tasks we need to add these header files first.
     Two formats are mostly used

  •       # include -  Searches for the specified header file in the current directory in which it's specified.
  •       #include "Header_File_Name" - In the specified path as well as standard directories as specified by /I compiler.

          b. -- Header file

It contains the C declarations and macro(any valid identifier in C even if it's a keyword) definitions. 
      example- stdio.h,conio.h,strings.h


                      2. main()

A function like all other functions except the difference between main() function and other functions are that main() is called by the Operating System when the user runs it.
   It's the first line compiled by C and is a predefined function in C program.
     It's mandatory to use main() function before adding codes in it.
      
For more notes and better clarifications you can reply me, I'll send you the notes prepared by me and hope will be releasing them soon...

Keep Smiling and don't forget to contact me for further assistance. Your Friendly Coder. SPrince

Comments

Popular posts from this blog

Introduction To Pointers

Introduction To C