about-text

SoftOSet is the most remarkable programming site. SoftOSet provides the fresh conceptual and professional programs, articles, books, and other interesting and technical writings. SoftOSet is the most reliable programming site to learn the programs and the basics of the popular programming languages. SoftOSet is the hub of the informative and research based articles.

Program Structure in C language


Basic program syntax/structure in C language

To be efficient in any programming language you must efficiently know its basic syntax and program structure. With this key point in mind we are going to demonstrate the basic program structure of C language.


                          Rules for Program creation


There are rules for the constant and variables creation. There will be the rules for the program creation. These rules are as under.


Ø  Write each instruction as a single statement.

Ø  Write statements in a sequential order.

Ø  Increase the readability by managing design of code.

Ø  Use loser case letter while coding.

Ø  Semi colon is statement terminator, so it will be used after all statements.

 

Hello World Program in C Language


Code


#include<stdio.h>                //header file and standard library

int main()                               //main function

{

printf(“Hello World in 2020”);                       //output statement

return 0;                                                            /*control return to System*/

}


Output


Simply this program has printed the Hello World in 2020 on screen.

 

 

Hello world Program in C


 

 

Explanation


Now we are just going to demonstrate each statement of this program in detail, so that beginners can understand it well.


#include


It is the header file or Pre processor directive which tells the compiler to include the special library which is written next to it.


<stdio.h>      


This is the standard input output library in the c language. Output and input functions such as printf() and scanf() defined in it.


int main()     


It is a statement of main function. Function is block of code in programming which execute sequentially. So the main function will execute from its starting curly brace to ending curly brace. It is here declared int, it can also be declared as void.


One thing is to be noted that a program in C language will never be execute until it has main function. And when a function executes, it starts execution from the main function, so main function is very important.       

printf(“Hello World in 2020 “);        

         

printf() is a standard output function defined in the library <stdio.h>. It is a printf statement terminated with ;. You can write anything to print on screen in printf() in between double quotes.


return 0;            


This statement will simply return the control of execution back to system after execution of program.

 

 

I hope you have grasped some points from this program. It was the simple program to understand the syntax of C language. Now we will cover up another program to further clarify your concepts.

 

Hello World Program in C Language


Code


#include<stdio.h>                //header file and standard library

int main()                               //main function

{

int a;

printf(“Enter A Number”);                           //output statement

scanf(“%d”,&a);                                      //input statement

printf(“You have Entered %d”,a);              //output statement

return 0;                                                            /*control return to System*/

}


Output


Simply this program has printed that has taken a number from user and display it on screen.

 

 

Basic input output structure in C language

Explanation


Here just two statements are unfamiliar to you so I will explain only these two statements.

First we have declared an int type variable which means integer. The first printf() statement will display a message on screen to enter a number same is it done in above program.


scanf(“%d”,&a);                                      //input statement


scan is the standard input function defined in the library of <stdio.h>


This input statement will take the input from user as “a” and stored the value of “a” in the address of “a”. You can give any name to this variable “a”. When we write the scanf()statement the compiler will automatically understand that here has to take some input. In scanf() %d is the format specifier for integer type data. When we write %d the compiler will understand here is integer type data.


And &a refers to the memory location or address of “a”, means where to store the value of a.


Some other format specifiers are


%f                       for real or float type data

%c                      for character type data

&s                        for string type data

 

Format Specifier in C language

 

printf(“You have Entered %d”,a);              //output statement


You are familiar with printf() statement but here we have used the format specifier %d means here exist an integer type value. And which value it is given outside quotation that is a. So this statement will print the value input by user.

 

Thanks read it, understand it, practice it and applied it.


Post a Comment

Feel Free to Comment Us

Previous Post Next Post

Recents