C Program Structure and components of This Structure

C Program Structure

Hello Friends This is another important Tutorial on C Programming Tutorial Series. In this tutorial, today we will learn the basic structure of the C program and also learn the different elements used in that basic structure.

C program normally a collection of some functions while in turn, these functions are the collection of some control statements or set of instructions. These sets of statements are used to guide the compiler to execute the program accordingly. Below is a basic Syntax of a General C program structure.

/*------------ Comment(s) ---------- */
Preprocessor directives #
Global Variables
main()
{
Local Variables;
Program Statements;
}
function()
{
Local Variables;
Program Statements;
}

Comments

These are used as a basic message, the main purpose of which is to convey a message to a programmer, which specifies how the execution of this code will be or what is the exact meaning of this code. It can be written anywhere in a C program. A special method is used to write to them. Any comment will be written between two symbols (/*—-*/). These symbols are called delimiters. Comments are basically the documentation of the program or piece of code. They ate there because if any other or new programmer and see the code already written, then the programmer can understand the working of that code on the basis of this comment.

Preprocessor Directives

These are the directives are executed before any C program goes to the compiler. These directives are processed through the preprocessors. There are two most commonly used preprocessor directives #Include and #define. #include loads the necessary library functions to the C program. While the other directive #define is used to define a variable globally. Its other name is macros.

Functions

A c program can also be called a collection of functions. Functions mainly contain some set of programming statements. A  program can have more than one function. If a program has only one function, that function is only the main(). The main() function is necessary for a program since the program execution starts from the main() function. There are only two types of functions, one is the library function and the other user-defined function The user-defined functions can be defined anywhere in a program.

Variables

A variable is only a placeholder. Variables are used to hold a value. The score of a variable is limited to only those functions in which they are declared. If we want to use a variable in more than one function or in the entire program, then we have to declare it outside the main function. Such variables are also named as global variables, while the variables declared in a particular function are called local variables.

Statements

Statements are mainly set of program instructions. They are always executed within those functions in which they are written.

Leave a Comment

Your email address will not be published. Required fields are marked *