C Program Structure

Programs are a sequence of instructions or statements. These statements form the structure of a C program. The C program structure is divided into various sections.

C Program Structure basically consists of the following parts:

Preprocessor Commands/ headers
Functions/ member functions
Variables.
Statement & Expressions.
Comments.

Program Structure of “Hello world” in C

Output:

Hello World” Program Structure in C

Let’s understand this Program Structure :

Preprocessor Commands/Headers

A program includes various programming elements, such as built-in functions, classes, keywords, constants, operators, etc., that are already defined in the standard C++ library. In order to use such pre-defined elements in a program, an appropriate header must be included in the program. The standard headers contain information, such as prototype, definition and return type of library functions, the data type of constants, etc. As a result, programmers do not need to explicitly declare (or define) the pre-defined programming elements. Standard headers are specified in a program through the preprocessor directive #include.

Header File

While writing a program we use several keywords & statements and functions such as printf(), scanf() etc. The file that has definitions of these functions needs to be included in the program. In the above program, we have used stdio.h. There are several libraries and “stdio.h” is one of the Header file, which is used for reading the data from the terminal and to display the data on the terminal.

main() function

The main() is a startup function that starts the execution of a C program. All C++ statements that need to be executed are written within main()

Comment:

Comments are a vital element of a program that is used to increase the readability of a program and to describe its functioning. Comments are not executable statements and hence do not increase the size of a file.

C supports two comment styles: Double slash (// ) is used to represent single-line comments and Multiline comments are used to define multiple lines descriptions that start with /* and ends with */. Comments are not important but, it’s a good practice if you use them, it improves the readability of the code. A program can have any number of comments.

Question-Related to C Program Structure