Thursday 9 June 2016

How To Write A Simple 'C' Program ?

How To Write A Simple 'C' Program ?

programming is learnt by doing it not by reading concerning it.learning a artificial language is like learning the way to ride a cycle.You got to undertake it. you would possibly slip a couple of times and get hurt conjointly, how ever ultimately you'll learn it.The same is the true with with the programming. You have to write programs to learn programming. Do not worry and do not be afraid of programming. It is a wonderful world. The more you do , the more you enjoy -take my word. Now let us write our first C program. The following is a simple C program to display the given message on the screen.

I recommend Code Blocks as it is User Friendly Compared to Turbo C or Turbo C++.
Since it is a first program i am going to explain how to use Code Blocks.
If you don't have Code Blocks Download From{>>>HERE!<<<}

STEP 1 :Open the Code Blocks IDE !

STEP 2: Go-to File Menu Select Empty File.

STEP  3:  Save the file! I recommend Saving the file with a suitable name related to the program you are writing.So basically we are writing C programming so save the file With name.C where ' .C ' is the extension.


STEP 4: Write the program !! the program written below follows the basic syntax.
the syntax of the functions printf( ), main(), Will be explained  in further posts.
but For now printf("  ");
displays whatever written in the double Quotes.
STEP 5: After writing the program you have to compile or build(Ctrl + F9) the program, code blocks being an intelligent IDE give errors you can see them after you click the highlighted icon in the image below. if no errors proceed if you find errors correct them and then run(Ctrl + F10).


Explanation of The C program!

LINE  1: /*Program to Display a message on the screen*/
 It is a comment or remark. We give comments to make Program more readable.Comments in C start with /*(slash and asterisk) and with */(asterisk and slash) Combination. A comment can be given in multiple lines also.
LINE 2:  #include
This is a Processor Command. #include command is used to copy the contents of the given file into your program. In this example #include is used to include the contents of stdio.h header file. Though this is not mandatory it is better to include the header file ( .h files are called as header files )
using #include command. We will discuss more about #include in My Post About Header files  
LINE 3: main( )
Each C Program starts with a function called main. Program's Execution starts with main function and ends with main function . All the remaining functions
 ( standard and user defined functions) are called from main functions. When main function is terminated , the program is deemed to be terminated.
LINE 4-Line 8 : {........}
Each function contains a set of instructions enclosed in { }(braces). The statements given between braces will be executed when function is executed whenever you run a C program , all the statements given between { } of main function will be executed. A set of statements enclosed within { } are also called as a BLOCK. In other Words For each function you have a block and that block is executed whenever the function is called.
LINE 4 starts the BLOCK and LINE 8 Ends the Block.
LINE 6: printf( " " );
Function printf() is a standard function in C language. It is used to display the given values on to standard output device (Screen or Projector etc.).
Whatever value is given in double Quotes (" ") it is called as string literal. When a string literal is passed to pintf function , it will print it as it is. When you supply values to function , you have to supply values to function , you have to supply values by enclosing them in parenthesis So, the values that is to be displayed by printf is given within parenthesis. 
Every statement in C is to be terminated with ( ; ) That is why there is a semicolon at the end of the statement.
That is about the first program we have written in this blog.
Later in this We will learn how to enhance display using escape sequence characters.
OUTPUT:














0 comments:

Post a Comment