Structure of C language

In this article, I am going to explain the structure of the C language. How to write any program in C by knowing its syntax. Let's look at the topic.

There are some rules to write a program in any language, such type of rules are called syntax. In shortly a syntax is a set of rules to write a program. Now, look at the syntax for writing a program in c language.

//Syntax for writing a program in C language
  1-#include<stdio.h>(Header files declaration)
  2-Global variables in c
  3-Constants in programs
  4-Declaration of function in c
  5-void main(){


  6-void function(){   ( User defined Function In C)

1- #include<stdio.h> is a statement that tells the compiler to insert the contents of stdio at a               particular place in a program. stdio.h is the header file for standard input and output functions.
it is a library where all input and output functions contain, for example, inbuilt functions like printf, scanf belong to this library only. so it is very important to declare header files before we use the inbuilt functions. if we did not write headers and inbuilt functions are used in a program, then compiler raises an error

2. Global Variables in C-To use the variables throughout the program, we declare Global type of variables here.

3. Constants-  these are variables that should not be changed throughout the program if we try to change the initialized value of variable compiler raises an error. suppose if declare the pie value as 3.14 it cannot be changed throughout the program we will look at the syntax now-

//Syntax for declaration and initialization of Constant in C
  const type constant_name;
  const float PI=3.14;
4. Declaration of functions in C-Before we write any user-defined function we must declare its prototype before the main is optional but if we write function prototype it will be better to Understand. Now we look at the syntax of the declaration of function before the main function. we will discuss parameters passing in later sections

  //Syntax for function prototype
    void funtion_name(type of data);

 5.void main()-this is the main part of the program, where the actual execution of the program starts. if you write any number of functions outside the main functions, without calling from main function,  it is useless as you don't see any output. you must call from main function if user-defined functions are written.

6. A user-defined function-A function is a block that contains a set of statements which perform specific task .a User-defined function is a function which is written outside main invoke the user-defined function you call it from the main function.this is the basic structure of c language, I will explain in detail later tutorials

Post a comment