Flow of C Progam

The C program follows many steps in execution. To understand the flow of C program well, let us see a simple program first.
#include <stdio.h>
  void main( ) {
  printf("hello catchmecoder");
Let's try to understand the flow of above program by the figure given below.

1) C program (source code) is sent to preprocessor first. The preprocessor is responsible to convert preprocessor directives into their respective values. The preprocessor generates an expanded source code.
2) Expanded source code is sent to compiler which compiles the code and converts it into assembly code.
3) The assembly code is sent to assembler which assembles the code and converts it into object code. Now a simple.obj file is generated.
4) The object code is sent to linker which links it to the library such as header files. Then it is converted into executable code. A simple.exe file is generated.
5) The executable code is sent to loader which loads it into memory and then it is executed. After execution, output is sent to console.

printf scanf in C

The printf() and scanf() functions are used for input and output in C language. Both functions are inbuilt library functions, defined in stdio.h (header file).

printf() function
The printf() functionis used for output. It prints the given statement to the default i/o device console.
The syntax of printf() function is given below:
printf("format string",argument_list);
The format string can be %d (integer), %c (character), %s (string), %f (float), %u(unsigned),..etc.
Scanf() function
The scanf() function is used for input. It reads the input data from the console.
scanf("format string",argument_list);

Program to print square of 2 numbers

Let's see a simple example of input and output in C language that prints square of 2 numbers.

#include <stdio.h>
void main( )  {  
int number; 
printf("enter a number:");  
printf("square of number is:%d ",number*number);  
enter a number:10
square of number is:100
The scanf("%d",&number) statement reads integer number from the console and stores the given value in number variable.
The printf("square of number is:%d ",number*number) statement prints the square of number on the console.

Program to print sum of 2 numbers

Let's see a simple example of input and output in C language that prints addition of 2 numbers.
#include <stdio.h>
void main( )  {   
int x = 0, y = 0, result = 0;  
printf("enter first number:");  
printf("enter second number:");  
printf("sum of 2 numbers:%d ",result);  
enter first number: 10
enter second number: 12
sum of 2 numbers: 22