C Language Program Structure Learner

A typical C program has the following structure:

Preprocessor Directives: These directives provide instructions to the compiler about what to do before compiling the source code. For example, the #include directive is used to include header files in the program.

Main function: This is the starting point of the program. The main function contains the code that the program will execute.

Variables: Variables are used to store data in the program. They must be declared with a specific data type (e.g., int, char, float) before they can be used.

Statements and Expressions: The code in the main function is composed of statements and expressions. Statements are instructions that perform a specific task (e.g., assignment, input/output). Expressions are used to perform calculations or comparisons.

Functions: Functions are self-contained blocks of code that can be called from the main function or from other functions. Functions can accept parameters and return values.

Return statement: The return statement is used to return a value from the main function or from a function.

End of the program: The end of the program is marked by the closing brace ‘}’ of the main function.

#include <stdio.h>

int add(int a, int b)
{
   return a + b;
}

int main()
{
   int num1, num2, sum;
   printf("Enter two numbers: ");
   scanf("%d %d", &num1, &num2);
   sum = add(num1, num2);
   printf("The sum is: %d", sum);
   return 0;
}