DAY 01 : STRUCTURE OF A C PROGRAM
#100DaysCodeChallenge

C Programming Language is one among the prominent and well renowned language used widely among all coders. It is deemed to be the robust language with rich set of in-built functions which plays a pivotal role in writing codes for complex programs. It is known to combine the features of assembly language and high-level language. This characteristic of C language makes it best suited for writing system software. It enables the user to concentrate on the problem instead of worrying about the machine code. The most noted point of the language is that, it is relatively easy to learn when compared with other languages. C Programming Language forms the basis for all other programming languages. To learn this language, first we need to know the structure of a C Program.
STRUCTURE :
The structure of a C Programming basically has three components namely,
- Preprocessor commands
- Global declarations
- Functions
PREPROCESSOR COMMANDS :
The preprocessor commands has special instructions within it and prepares the program for compilation. The command include is a preprocessor command which depicts that the program needs an information from the header file to execute the program. All these commands start with a hash (#) symbol. The header file follows the preprocessor command include. For example,
#include <stdio.h>
In the above, stdio is the header file in which std represents standard, i represents input and o represents output. stdio is the standard input/output library. #include tells to include all the in-built functions in the header file life printf.
GLOBAL DECLARATIONS :
Global declarations mainly include main() function. This function is starting point for execution. It is also known as the entry point of execution of program. Being mandatory for all programs, it is placed just after the preprocessor commands.
#include <stdio.h> main()
The prominent fact is that the main() function contains numerous functions within it and calls the functions for execution. Hence, it is called the "calling function". The main() function follows the "Top-Down Approach", i.e., the main() functions has many functions such as FuncA, FuncB, FuncC and so on and these functions are divided into FuncA1,FuncA2 and so on. This is top-down approach.

#include <stdio.h> int main()
The main() function returns a value the operating system after executing all the statements. This value is an integer. So we mention it as int main().
FUNCTIONS :
Functions are a set of instructions to perform a specified or a particular task. These has two components namely, >>Local Declarations >>Statements.

The local declarations and statements under functions are always enclosed within curly brackets and forms a function body. The local declarations are the data declared within a function and visible only to that function. It executes only within that particular function. The statements follow up the local declarations. It manipulates the data to perform task.
The basic structure of a C Program is as follows :

All the statements in the C Program is followed up by a semicolon. Indentations are also important while writing a code in C language.
EXAMPLE PROGRAM :
Let us now write a simple C program to print 'WELCOME' for clear understanding of the structure.
The code is as follows :

Now in the above code, we have the preprocessor command with a hash symbol (#include) followed by a header file 'stdio.h'. Next, we have the global declaration main() function preceeded with int operator. Then we have our curly brackets open to constitute a function body with statements. The printf is a in-built function from the header file stdio.h declared at the start of the code. Inside printf command we are supposed to give the text that needs to be displayed within quotes. A semicolon must follow each and every statement within the function body. Then comes the return statement. At last, we close the curly brackets depicting the end of the function.
The output is as follows:

#100DaysCodeChallenge
Have a great day friends!!
Thank you!!
About the Creator
Preethi Siva
Writing is not my hobby.........
It comes when my heart is connected to my soul and says to write!!!




Comments
There are no comments for this story
Be the first to respond and start the conversation.