Basic structure of a C language

Preprocessor directives: The compiler can be instructed to include header files or define constants using these lines of code, which begin with the # symbol. For example:
#include <stdio.h>
#define PI 3.14159
Function Declarations: These are the prototypes of functions that are defined later in the program. They tell the compiler what arguments the functions take and what their return types are. For example:
int add(int a, int b);
void greet(char* name);
Global Variables: These are variables that are declared outside of any function and can be accessed by any function in the program. For example:
int count = 0;
char* message = "Hello, world!";
Main Function: This is the starting point of the program and is where the program begins executing. It must be defined in every C program and returns an integer value. For example:
int main() {
// program statements go here
return 0;
}
Function Definitions: These are the implementations of the functions declared earlier in the program. They contain the actual code that gets executed when the functions are called. For example:
int add(int a, int b) {
return a + b;
}
void greet(char* name) {
printf("Hello, %s!\n", name);
}
Here is a complete example of a C program that demonstrates the basic structure:
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
This program includes the standard input/output library (<stdio.h>), which is necessary for the printf() function used to output the “Hello, World!” message to the console.
The main() function is the entry point of the program and is where the execution begins. In this example, the printf() function is called to output the message “Hello, World!” to the console. The return 0; statement indicates that the program has been completed successfully.
This is just a simple example, but it illustrates the basic structure of a C program: the inclusion of necessary libraries, the declaration of functions (such as main()), and the execution of statements within those functions.