Breaking News

Basic Structure In C Programming Language

Basic Structure In C Programming Language - Technotoken



To better understand the C programming language we must first know the basic functioning of c programming and in order to accomplish that we need to start by understanding the basic structure of a c program and all the different parts that complete it. 

So without any further a due let's get started




Structure of C Program 


The structure of the C programming language is relatively easy as compared to other programming languages.

The basic structure of the c program is given below.
Header File

Global Variables

void main()

{
    Variable Declaration;
    Variable Initialization;

Statement 1;
Statement 2;

}

Header Files


Header files are files which contain the code for inbuilt or library functions like Printf(), scanf(), getch().

These files have to be used on the top of the c program to invoke the functions which you are going to use in the respective program.

Syntax

 #include <file>

Examples 


  • Standard Input / Output Header File
 #include<stdio.h>

  • Console Input / Output Header File
#include<conio.h>

#include<string.h> 

#include<maths.h> 

  • Standard Library Header File
#include<stdlib.h>


Global Variables


The variables defined above main() are called global variables. These variables are accessible to other parts of the program. We can even pre initialize the global variables using the operator for assignment.


Examples


int sum=0,n=10;  /* Global Variable Declaration */

main()
{

statement 1;
statement 2;

}


Variable Declaration

Variables tend to perform the key role when it comes to performing calculations accordingly as per the demand of the program. However there are various types of variables one can use in c, also the base value of each variable differs depending upon what type of variable it is. To offer assurance to the compiler that a variable of the given type and name exists, allowing the compiler to continue compilation without needing all of the variable's details Variable declarations are used in C Programming Language.


Syntax

Datatype Variable name;

Datatype Variable 1, Variable 2;

Examples


int a;

int a,b,c; 

float average; 


Variable Initialization


Now when you have declared variables the next step is to initialize the variables with their respective values. To do this Variable initialization is used. 


Syntax

Datatype Variable name = Variable Value;

Datatype Variable 1 name = Variable Value, Variable 2 name = Variable Value;

Examples


int a = 2;

int a = 1, b = 5, c = 6;  

Frequently Asked Questions



So this is it guys today we just scratched the surface when it comes to what c programming language has to offer. If you want us to write more on this topic or have any particular queries regarding this post you can always comment or feel free to mail us at our official mail also, follow us on Instagram and Facebook to receive Latest Updates first.


Peace!!!

No comments

If you have any doubts, please let us Know.