To Build a C Program

Abhay Kumar Modi
HSR Hi-Tech Solutions
3 min readJun 11, 2020

Various components of structure of a C Program are:

  1. Header Files: A C Program always starts with at least one Header file.A header file is a file with extension .h which contains Predefined functions, declarations and macro definations to be shared between several source files.

Some of C Header files are:

  • stdio.h — Defines core input and output functions. (this file is used in almost every C program)
  • stdlib.h — Defines numeric conversion functions, pseudo-random network generator, memory allocation.
  • math.h — Defines common mathematical funtions.
  • string.h — Defines string handling funtions.
  • stdint.h — Defines exact width integer types.
  • stddef.h — Defines several useful types and macros.

Syntax to include a header file in C:

If we use predefined header file than we have to write the file name between<>; and when we want to use our own build .c then we have to write the file name with its location eg: C:\Users\Razz\Documents\practice.c.

2. Main Method Declaration: The second part of any C program is to declare the main() function. The syntax to declare the main function. If a C program has no main function then the C program will not run, so we have to use main function always in a C program.
Syntax to Declare main method:
(i). int main()
{
………
………
………
}

OR

(ii). void main()
{
……….
……….
……….
}

3. Variable Declaration: The next part of any C program is the variable declaration. It refers to the variables that are to be used in the function. Please note that in the C program, no variable can be used without being declared. Also in a C program, the variables are to be declared before any operation in the function.

Example:
int main()
{
int a;
……
…….

4. Body: Body of a function in C program, refers to the operations that are performed in the functions. It can be anything like manipulations, searching, sorting, printing, etc.

Example:int main()
{
int a;

printf("%d", a);

…….

…….

5. any C program is the return statement. The return statement refers to the returning of the values from a function. This return statement and return value depend upon the return type of the function. For example, if the return type is void, then there will be no return statement. In any other case, there will be a return statement and the return value will be of the type of the specified return type.

Example:
int main()
{
int a;
printf("%d", a);
return 0;
}

Your first C program:

int main()
{

int a;

a=7;

printf(“%d”,a);

return 0;

}

Output will be:- 7

We will discuss these all things in details in later blog.

--

--