Programming Basics in C (Autopsy of Basic way to Code in C)

-As the title suggest, it's an autopsy, i:e every BASIC ELEMENTS of C will be dissected and offered the easiest relevancy of it in C programming.

 --- Let's continue with the Basics for every newbie asking why this specific way is used in C.

The table below illustrates every specific components in Basic C Program.

  Elements
                                                   Description
#include
The C programming language provides many standard library functions for file input and output. 

These functions make up the bulk of the C standard library header stdio.h.

main()
Execution of any C program starts at this point.
 This is where the compilation process starts. 

This is like all other functions except that it’s called by OS when user runs the program.

{ } (Curly Braces)
These braces are used to group a set of statements. 

These are used to declare a block for a function, conditional statements and loops where  {  marks a start and }  marks the end.

 Any statement inside these {} has visibility and life inside the block.

/*…. */ (multiline comment)
This is to make program codes clear to users and make them understand the relevancy of codes when they read it. 

These lines are excluded by compiler while compilation. 
printf(“…”);
A function included in standard input/ output(stdio.h) header file, where printf() is an output function.

 printf is used to print anything over the terminal window(Black Screen Output Window ), to give information about some value.
scanf();
A function included in standard input/output(stdio.h) header file, where scanf() is an input function. 

scanf() is used to scan a value which users input to perform an operation as proposed by coders output.
getch();
This is a function of console  input/output(conio.h) header file.

 It holds the screen and waits until user keystrokes a value. Mostly used to hold output screen in MSDOS compilers, like Turbo C++.
conio.h

A console input/output header file for many important functions for MSDOS compilers, including getch().

;  (semi-colon)

Used to distinguish two statements by providing a clear boundary between them.

Known as the statement Terminator. Remember it’s to terminate statements and not user created functions or blocks or loops or conditional statements.
return 0;

Every function has a return type which  terminated the function and returns the console back to calling function. in main(), it’s used to tell the compiler about the exit code for a program, where 0 states normal exit and non-zero an abnormal exit.



Now, This is the time to explain it over the edge.
This IS Where You Need To GO.

          A Basic C Program and Components Specifications.

/* A Basic Program to perform addition by taking two numbers as input
      it's a user based input program.
      code 1.1    
-   This is how we write a multi- line documentation comment, to inform
     user about the code.*/ 

#include< stdio.h>
#include<conio.h>
 int main()                 //point of compilation. every C program has it, int is return type of main
{                                     // Starting of main function, a block of codes
 int a,b;                        // initialization of variables,to store values in memory ( discussed later )
printf("\n Enter the first Value");     // printing an output to inform user what to do.
scanf("%d",&a) ;                       // getting input made by user, %d , & discussed later
printf("\n Enter Second Value");  // As said above 
scanf("%d",&b);           // As said above.
printf("\n the added value is %d " , a+b);
getch();     // to hold output screen, only for MS DOS compiler like TURBO C++
return 0;
}             // end to compilation. termination of main
Above Program In TURBO C++


Output of Above Program.
...

The above code is written in Turbo C++ and hence conio.h as well as getch() is used. you dont have to use it if you use any other compiler as i've suggested in older post.

Make sure to contact me when you need any assistance..
Regards,
Xavier.


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